From patchwork Fri Jul 13 16:10:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: stephen hemminger X-Patchwork-Id: 170913 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id E2AD12C02F3 for ; Sat, 14 Jul 2012 02:10:41 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756668Ab2GMQKf (ORCPT ); Fri, 13 Jul 2012 12:10:35 -0400 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 Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.vyatta.com (Postfix) with ESMTP id 145A6141034D; Fri, 13 Jul 2012 09:10:19 -0700 (PDT) X-Virus-Scanned: amavisd-new at tahiti.vyatta.com Received: from mail.vyatta.com ([127.0.0.1]) by localhost (mail.vyatta.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id si3oAdGp6GXP; Fri, 13 Jul 2012 09:10:18 -0700 (PDT) Received: from nehalam.linuxnetplumber.net (static-50-53-80-93.bvtn.or.frontiernet.net [50.53.80.93]) by mail.vyatta.com (Postfix) with ESMTPSA id 0318C14101DB; Fri, 13 Jul 2012 09:10:17 -0700 (PDT) Date: Fri, 13 Jul 2012 09:10:02 -0700 From: Stephen Hemminger To: Pravin B Shelar Cc: netdev@vger.kernel.org, jpettit@nicira.com, jesse@nicira.com Subject: Re: [PATCH] iproute2: Fix memory hog of ip batched command. Message-ID: <20120713091002.3729398e@nehalam.linuxnetplumber.net> In-Reply-To: <1342142466-28270-1-git-send-email-pshelar@nicira.com> References: <1342142466-28270-1-git-send-email-pshelar@nicira.com> Organization: Vyatta X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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. --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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; } }