diff options
author | Nishant Chaprana <n.chaprana@samsung.com> | 2016-03-08 20:23:18 +0530 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2016-03-09 14:58:42 +0200 |
commit | 24a200efed42325b77512559dd638a548d425791 (patch) | |
tree | cd3d2b612b76a69d85b23352de78b517c96bcd6c | |
parent | 9e96310aeef8aefc8de1b41ade21ad0cc1e17788 (diff) | |
download | connman-24a200efed42325b77512559dd638a548d425791.tar.gz |
src: Fix memory leak when realloc fails
-rw-r--r-- | src/inet.c | 8 | ||||
-rw-r--r-- | vpn/vpn-provider.c | 11 |
2 files changed, 16 insertions, 3 deletions
@@ -2648,8 +2648,14 @@ char **__connman_inet_get_running_interfaces(void) g_free(ifr); - if (count < numif) + if (count < numif) { + char **prev_result = result; result = g_try_realloc(result, (count + 1) * sizeof(char *)); + if (!result) { + g_free(prev_result); + goto error; + } + } return result; diff --git a/vpn/vpn-provider.c b/vpn/vpn-provider.c index afd7ca6b..2c717fc5 100644 --- a/vpn/vpn-provider.c +++ b/vpn/vpn-provider.c @@ -811,16 +811,20 @@ static gchar **create_network_list(GSList *networks, gsize *count) { GSList *list; gchar **result = NULL; + gchar **prev_result; unsigned int num_elems = 0; for (list = networks; list; list = g_slist_next(list)) { struct vpn_route *route = list->data; int family; + prev_result = result; result = g_try_realloc(result, (num_elems + 1) * sizeof(gchar *)); - if (!result) + if (!result) { + g_free(prev_result); return NULL; + } switch (route->family) { case AF_INET: @@ -841,9 +845,12 @@ static gchar **create_network_list(GSList *networks, gsize *count) num_elems++; } + prev_result = result; result = g_try_realloc(result, (num_elems + 1) * sizeof(gchar *)); - if (!result) + if (!result) { + g_free(prev_result); return NULL; + } result[num_elems] = NULL; *count = num_elems; |