From c3a70a9536fd3a288a886d4e99618e1c70e48b22 Mon Sep 17 00:00:00 2001 From: Chih-Hung Chou Date: Tue, 18 Sep 2012 10:38:08 -0300 Subject: fix memory leaking There is a possible memory leaking when lo is allocated but the lo->name is not. In this case, we should free the lo and then return original change I475968bd570a113c9f61f02b974d57d1caaa0236 picked from: https://android-review.googlesource.com/#/c/23450/ as seen on: http://review.cyanogenmod.com/#/c/13782/ Change-Id: I21dd3267fa2521578d93f7b1a7bc2a6726de15ac --- src/network.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/network.c b/src/network.c index b0ffc6b..2dba31c 100755 --- a/src/network.c +++ b/src/network.c @@ -162,14 +162,17 @@ static int iface_allowed(struct irec **irecp, int if_index, break; } - if (!lo && - (lo = whine_malloc(sizeof(struct iname))) && - (lo->name = whine_malloc(strlen(ifr.ifr_name)+1))) - { - strcpy(lo->name, ifr.ifr_name); - lo->isloop = lo->used = 1; - lo->next = daemon->if_names; - daemon->if_names = lo; + if (!lo && (lo = whine_malloc(sizeof(struct iname)))) + { + if ((lo->name = whine_malloc(strlen(ifr.ifr_name)+1))) + { + strcpy(lo->name, ifr.ifr_name); + lo->isloop = lo->used = 1; + lo->next = daemon->if_names; + daemon->if_names = lo; + } else { + free(lo); + } } } -- cgit v1.2.3