summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNishant Chaprana <n.chaprana@samsung.com>2016-03-08 20:23:18 +0530
committerPatrik Flykt <patrik.flykt@linux.intel.com>2016-03-09 14:58:42 +0200
commit24a200efed42325b77512559dd638a548d425791 (patch)
treecd3d2b612b76a69d85b23352de78b517c96bcd6c
parent9e96310aeef8aefc8de1b41ade21ad0cc1e17788 (diff)
downloadconnman-24a200efed42325b77512559dd638a548d425791.tar.gz
src: Fix memory leak when realloc fails
-rw-r--r--src/inet.c8
-rw-r--r--vpn/vpn-provider.c11
2 files changed, 16 insertions, 3 deletions
diff --git a/src/inet.c b/src/inet.c
index dc788eaa..69ded19d 100644
--- a/src/inet.c
+++ b/src/inet.c
@@ -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;