From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id B079A697B for ; Thu, 12 May 2016 09:55:55 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 12 May 2016 00:55:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,609,1455004800"; d="scan'208";a="804557606" Received: from smonroyx-mobl.ger.corp.intel.com (HELO [10.237.221.39]) ([10.237.221.39]) by orsmga003.jf.intel.com with ESMTP; 12 May 2016 00:55:28 -0700 From: Sergio Gonzalez Monroy To: Daniel Mrzyglod Cc: dev@dpdk.org, david.marchand@6wind.com References: <1462982465-129762-1-git-send-email-danielx.t.mrzyglod@intel.com> Message-ID: <72463300-a846-43a7-11d4-65a48b6370d0@intel.com> Date: Thu, 12 May 2016 08:55:27 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <1462982465-129762-1-git-send-email-danielx.t.mrzyglod@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH] eal/linuxapp: fix resource leak X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 May 2016 07:55:56 -0000 Hi, On 11/05/2016 17:01, Daniel Mrzyglod wrote: > Fix issue reported by Coverity. > Coverity ID 97920 > > munmap structure of hugepage > > leaked_storage: Variable hugepage going out of scope leaks the storage > it points to. > > The system resource will not be reclaimed and reused, reducing the future > availability of the resource. I'm not really fond of this commit messages, but if no one minds them, so be it. > In rte_eal_hugepage_init: Leak of memory or pointers to system resources > > Fixes: b6a468ad41d5 ("memory: add --socket-mem option") > > Signed-off-by: Daniel Mrzyglod > --- > lib/librte_eal/linuxapp/eal/eal_memory.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c > index 5b9132c..cd40cc9 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_memory.c > +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c > @@ -1051,7 +1051,7 @@ int > rte_eal_hugepage_init(void) > { > struct rte_mem_config *mcfg; > - struct hugepage_file *hugepage, *tmp_hp = NULL; > + struct hugepage_file *hugepage = NULL, *tmp_hp = NULL; > struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES]; > > uint64_t memory[RTE_MAX_NUMA_NODES]; > @@ -1374,6 +1374,8 @@ rte_eal_hugepage_init(void) > > fail: > free(tmp_hp); > + if (hugepage != NULL) > + munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file)); > return -1; > } > You missed the last conditional if(...0 of the function where it returns directly with error value. Looking at the code a bit, we never check for anything other than < 0 return value, so I'd just do a 'goto fail' instead. Sergio