From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Hemminger Subject: Re: [PATCH] iproute2: Fix memory hog of ip batched command. Date: Fri, 13 Jul 2012 09:10:02 -0700 Message-ID: <20120713091002.3729398e@nehalam.linuxnetplumber.net> References: <1342142466-28270-1-git-send-email-pshelar@nicira.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: netdev@vger.kernel.org, jpettit@nicira.com, jesse@nicira.com To: Pravin B Shelar Return-path: Received: from mail.vyatta.com ([76.74.103.46]:33701 "EHLO mail.vyatta.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755260Ab2GMQKT (ORCPT ); Fri, 13 Jul 2012 12:10:19 -0400 In-Reply-To: <1342142466-28270-1-git-send-email-pshelar@nicira.com> Sender: netdev-owner@vger.kernel.org List-ID: On Thu, 12 Jul 2012 18:21:06 -0700 Pravin B Shelar wrote: > ipaddr_list_or_flush() builds list of all device at start of > every flush or list operation, but does not free memory at end. > This can hog lot of memory for large batched command. > Following patch fixes it. > > Reported-by: Justin Pettit > Signed-off-by: Pravin B Shelar Given all the conditional's and goto's this introduces, I prefer to refactor the code to split up the large function. There is an additional leak here where element is pruned from list and not freed. diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 1db7fd0..5e03d1e 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -1011,9 +1011,10 @@ flush_done: ok = 1; break; } - if (!ok) + if (!ok) { *lp = l->next; - else + free(l); + } else lp = &l->next; } }