core: fix memleak in nm_utils_get_start_time_for_pid() and parsing start-time
It was leaking @tokens in case of error. Also the error checking of start-time with strtoull() was erroneous.
This commit is contained in:
@@ -371,10 +371,10 @@ guint64
|
|||||||
nm_utils_get_start_time_for_pid (pid_t pid, char *out_state)
|
nm_utils_get_start_time_for_pid (pid_t pid, char *out_state)
|
||||||
{
|
{
|
||||||
guint64 start_time;
|
guint64 start_time;
|
||||||
gchar *filename;
|
gs_free gchar *filename = NULL;
|
||||||
gchar *contents;
|
gs_free gchar *contents = NULL;
|
||||||
size_t length;
|
size_t length;
|
||||||
gchar **tokens;
|
gs_strfreev gchar **tokens = NULL;
|
||||||
guint num_tokens;
|
guint num_tokens;
|
||||||
gchar *p;
|
gchar *p;
|
||||||
gchar *endp;
|
gchar *endp;
|
||||||
@@ -410,19 +410,15 @@ nm_utils_get_start_time_for_pid (pid_t pid, char *out_state)
|
|||||||
if (num_tokens < 20)
|
if (num_tokens < 20)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
start_time = strtoull (tokens[19], &endp, 10);
|
start_time = strtoull (tokens[19], &endp, 10);
|
||||||
if (endp == tokens[19])
|
if (*endp != '\0' || errno != 0)
|
||||||
goto out;
|
start_time = 0;
|
||||||
|
|
||||||
g_strfreev (tokens);
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (out_state)
|
if (out_state)
|
||||||
*out_state = state;
|
*out_state = state;
|
||||||
|
|
||||||
g_free (filename);
|
|
||||||
g_free (contents);
|
|
||||||
|
|
||||||
return start_time;
|
return start_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user