diff options
author | Thomas Haller <thaller@redhat.com> | 2015-06-30 14:05:44 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-06-30 14:19:30 +0200 |
commit | 67057079a433a60523d0937b075b4203b4730c63 (patch) | |
tree | 3fee86681b97511a83885ce75cd29c2b001c44ba | |
parent | 4fbd42a0355c1a2438edd869908b1616b328af6c (diff) | |
download | NetworkManager-67057079a433a60523d0937b075b4203b4730c63.tar.gz |
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.
-rw-r--r-- | src/NetworkManagerUtils.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/NetworkManagerUtils.c b/src/NetworkManagerUtils.c index 579079bcc1..79c173825b 100644 --- a/src/NetworkManagerUtils.c +++ b/src/NetworkManagerUtils.c @@ -371,10 +371,10 @@ guint64 nm_utils_get_start_time_for_pid (pid_t pid, char *out_state) { guint64 start_time; - gchar *filename; - gchar *contents; + gs_free gchar *filename = NULL; + gs_free gchar *contents = NULL; size_t length; - gchar **tokens; + gs_strfreev gchar **tokens = NULL; guint num_tokens; gchar *p; gchar *endp; @@ -410,19 +410,15 @@ nm_utils_get_start_time_for_pid (pid_t pid, char *out_state) if (num_tokens < 20) goto out; + errno = 0; start_time = strtoull (tokens[19], &endp, 10); - if (endp == tokens[19]) - goto out; - - g_strfreev (tokens); + if (*endp != '\0' || errno != 0) + start_time = 0; - out: +out: if (out_state) *out_state = state; - g_free (filename); - g_free (contents); - return start_time; } |