From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 35DCBC3E2 for ; Wed, 15 Jun 2016 11:35:48 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 15 Jun 2016 02:35:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.26,475,1459839600"; d="scan'208";a="998015855" Received: from irsmsx151.ger.corp.intel.com ([163.33.192.59]) by orsmga002.jf.intel.com with ESMTP; 15 Jun 2016 02:35:47 -0700 Received: from irsmsx102.ger.corp.intel.com ([169.254.2.10]) by IRSMSX151.ger.corp.intel.com ([169.254.4.151]) with mapi id 14.03.0248.002; Wed, 15 Jun 2016 10:35:46 +0100 From: "Kerlin, MarcinX" To: "Gonzalez Monroy, Sergio" , "david.marchand@6wind.com" CC: "dev@dpdk.org" Thread-Topic: [PATCH v2 1/1] eal: fix resource leak of mapped memory Thread-Index: AQHRxkgA/RHXv6BhmEG4LfFmgmOzX5/qKDYAgAAc76A= Date: Wed, 15 Jun 2016 09:35:45 +0000 Message-ID: <68D830D942438745AD09BAFA99E33E8125EB2F@IRSMSX102.ger.corp.intel.com> References: <1461083251-31140-1-git-send-email-marcinx.kerlin@intel.com> <1465918435-30973-1-git-send-email-marcinx.kerlin@intel.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v2 1/1] eal: fix resource leak of mapped memory 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: Wed, 15 Jun 2016 09:35:49 -0000 Hi Sergio, Thanks for tips, I removed double casting and I leave (void *) casting beca= use pointer hp is const and compiler returns warnings. Regards, Marcin > -----Original Message----- > From: Gonzalez Monroy, Sergio > Sent: Wednesday, June 15, 2016 10:49 AM > To: Kerlin, MarcinX ; david.marchand@6wind.com > Cc: dev@dpdk.org > Subject: Re: [PATCH v2 1/1] eal: fix resource leak of mapped memory >=20 > Hi Marcin, >=20 > On 14/06/2016 16:33, Marcin Kerlin wrote: > > Patch fixes resource leak in rte_eal_hugepage_attach() where mapped > > files were not freed back to the OS in case of failure. Patch uses the > > behavior of Linux munmap: "It is not an error if the indicated range > > does not contain any mapped pages". > > > > Coverity issue: 13295, 13296, 13303 > > Fixes: af75078fece3 ("first public release") > > > > Signed-off-by: Marcin Kerlin > > --- > > lib/librte_eal/linuxapp/eal/eal_memory.c | 11 +++++++++-- > > 1 file changed, 9 insertions(+), 2 deletions(-) > > > > diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c > > b/lib/librte_eal/linuxapp/eal/eal_memory.c > > index 79d1d2d..1834fa0 100644 > > --- a/lib/librte_eal/linuxapp/eal/eal_memory.c > > +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c > > @@ -1417,7 +1417,7 @@ rte_eal_hugepage_attach(void) > > if (internal_config.xen_dom0_support) { > > #ifdef RTE_LIBRTE_XEN_DOM0 > > if (rte_xen_dom0_memory_attach() < 0) { > > - RTE_LOG(ERR, EAL,"Failed to attach memory setments > of primay " > > + RTE_LOG(ERR, EAL, "Failed to attach memory > segments of primary " > > "process\n"); >=20 > If you want to fix spelling of error message it probably should go in a d= ifferent > patch. >=20 > > return -1; > > } > > @@ -1481,7 +1481,7 @@ rte_eal_hugepage_attach(void) > > > > size =3D getFileSize(fd_hugepage); > > hp =3D mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd_hugepage, 0); > > - if (hp =3D=3D NULL) { > > + if (hp =3D=3D MAP_FAILED) { > > RTE_LOG(ERR, EAL, "Could not mmap %s\n", > eal_hugepage_info_path()); > > goto error; > > } > > @@ -1551,6 +1551,13 @@ rte_eal_hugepage_attach(void) > > return 0; > > > > error: > > + s =3D 0; > > + while (s < RTE_MAX_MEMSEG && mcfg->memseg[s].len > 0) { > > + munmap(mcfg->memseg[s].addr, mcfg->memseg[s].len); > > + s++; > > + } > > + if (hp !=3D NULL && hp !=3D MAP_FAILED) > > + munmap((void *)(uintptr_t)hp, size); >=20 > No need for double casting, nor to cast to (void *). >=20 > Sergio >=20 > > if (fd_zero >=3D 0) > > close(fd_zero); > > if (fd_hugepage >=3D 0) >=20