From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id D957A5690 for ; Thu, 19 Mar 2015 17:20:41 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP; 19 Mar 2015 09:20:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,430,1422950400"; d="scan'208";a="469569297" Received: from irsmsx110.ger.corp.intel.com ([163.33.3.25]) by FMSMGA003.fm.intel.com with ESMTP; 19 Mar 2015 09:20:40 -0700 Received: from irsmsx108.ger.corp.intel.com ([169.254.11.218]) by irsmsx110.ger.corp.intel.com ([169.254.15.236]) with mapi id 14.03.0195.001; Thu, 19 Mar 2015 16:20:39 +0000 From: "Iremonger, Bernard" To: Tetsuya Mukawa , "dev@dpdk.org" Thread-Topic: [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation Thread-Index: AQHQYJUf0Y3l/VBHxUeG4dL1PH33IJ0j/h8A Date: Thu, 19 Mar 2015 16:20:39 +0000 Message-ID: <8CEF83825BEC744B83065625E567D7C2049F3B77@IRSMSX108.ger.corp.intel.com> References: <1426155474-1596-4-git-send-email-mukawa@igel.co.jp> <1426584645-28828-1-git-send-email-mukawa@igel.co.jp> <1426584645-28828-4-git-send-email-mukawa@igel.co.jp> In-Reply-To: <1426584645-28828-4-git-send-email-mukawa@igel.co.jp> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation 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, 19 Mar 2015 16:20:42 -0000 > -----Original Message----- > From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp] > Sent: Tuesday, March 17, 2015 9:31 AM > To: dev@dpdk.org > Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa > Subject: [PATCH 3/6] eal: Fix memory leaks and needless incrementation of= pci uio implementation Hi Tetsuya, It would be better to reword "needless incrementation of pci uio implementa= tion" to "needless increment of pci_map_addr" in commit line. >=20 > When pci_map_resource() is failed but path is allocated correctly, path w= on't be freed. Also, when > open() is failed, uio_res won't be freed. > This patch fixes these memory leaks. > When pci_map_resource() is failed, mapaddr will be MAP_FAILED. > In this case, pci_map_addr should not be incremented. >=20 > Also, the patch fixes belows. Typo "belows" should be "below". Regards, Bernard. > - To shrink code, move close(). > - Remove fail variable. >=20 > Signed-off-by: Tetsuya Mukawa > --- > lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 28 ++++++++++++++-----------= --- > 1 file changed, 14 insertions(+), 14 deletions(-) >=20 > diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/l= inuxapp/eal/eal_pci_uio.c > index b971ec9..5044884 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > @@ -333,7 +333,6 @@ pci_uio_map_resource(struct rte_pci_device *dev) > maps =3D uio_res->maps; > for (i =3D 0, map_idx =3D 0; i !=3D PCI_MAX_RESOURCE; i++) { > int fd; > - int fail =3D 0; >=20 > /* skip empty BAR */ > phaddr =3D dev->mem_resource[i].phys_addr; @@ -347,6 +346,11 @@ > pci_uio_map_resource(struct rte_pci_device *dev) > loc->domain, loc->bus, loc->devid, loc->function, > i); >=20 > + /* allocate memory to keep path */ > + maps[map_idx].path =3D rte_malloc(NULL, strlen(devname) + 1, 0); > + if (maps[map_idx].path =3D=3D NULL) > + goto fail0; > + > /* > * open resource file, to mmap it > */ > @@ -354,7 +358,7 @@ pci_uio_map_resource(struct rte_pci_device *dev) > if (fd < 0) { > RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", > devname, strerror(errno)); > - return -1; > + goto fail1; > } >=20 > /* try mapping somewhere close to the end of hugepages */ @@ -363,23 += 367,13 @@ > pci_uio_map_resource(struct rte_pci_device *dev) >=20 > mapaddr =3D pci_map_resource(pci_map_addr, fd, 0, > (size_t)dev->mem_resource[i].len, 0); > + close(fd); > if (mapaddr =3D=3D MAP_FAILED) > - fail =3D 1; > + goto fail1; >=20 > pci_map_addr =3D RTE_PTR_ADD(mapaddr, > (size_t)dev->mem_resource[i].len); >=20 > - maps[map_idx].path =3D rte_malloc(NULL, strlen(devname) + 1, 0); > - if (maps[map_idx].path =3D=3D NULL) > - fail =3D 1; > - > - if (fail) { > - rte_free(uio_res); > - close(fd); > - return -1; > - } > - close(fd); > - > maps[map_idx].phaddr =3D dev->mem_resource[i].phys_addr; > maps[map_idx].size =3D dev->mem_resource[i].len; > maps[map_idx].addr =3D mapaddr; > @@ -394,6 +388,12 @@ pci_uio_map_resource(struct rte_pci_device *dev) > TAILQ_INSERT_TAIL(uio_res_list, uio_res, next); >=20 > return 0; > + > +fail1: > + rte_free(maps[map_idx].path); > +fail0: > + rte_free(uio_res); > + return -1; > } >=20 > #ifdef RTE_LIBRTE_EAL_HOTPLUG > -- > 1.9.1