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 D26A17EEF for ; Fri, 13 Mar 2015 15:04:22 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP; 13 Mar 2015 07:01:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,395,1422950400"; d="scan'208";a="691652346" Received: from irsmsx153.ger.corp.intel.com ([163.33.192.75]) by fmsmga002.fm.intel.com with ESMTP; 13 Mar 2015 07:04:20 -0700 Received: from irsmsx108.ger.corp.intel.com ([169.254.11.218]) by IRSMSX153.ger.corp.intel.com ([169.254.9.234]) with mapi id 14.03.0195.001; Fri, 13 Mar 2015 14:04:19 +0000 From: "Iremonger, Bernard" To: Tetsuya Mukawa , "dev@dpdk.org" Thread-Topic: [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource() Thread-Index: AQHQXK3o8kTNRME5/UythEALZbYysZ0ac10w Date: Fri, 13 Mar 2015 14:04:19 +0000 Message-ID: <8CEF83825BEC744B83065625E567D7C2049F2975@IRSMSX108.ger.corp.intel.com> References: <1425438703-18895-1-git-send-email-mukawa@igel.co.jp> <1426155474-1596-1-git-send-email-mukawa@igel.co.jp> <1426155474-1596-4-git-send-email-mukawa@igel.co.jp> In-Reply-To: <1426155474-1596-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.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource() 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: Fri, 13 Mar 2015 14:04:23 -0000 > -----Original Message----- > From: Tetsuya Mukawa [mailto:mukawa@igel.co.jp] > Sent: Thursday, March 12, 2015 10:18 AM > To: dev@dpdk.org > Cc: Iremonger, Bernard; Richardson, Bruce; Tetsuya Mukawa > Subject: [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource() >=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. >=20 > Signed-off-by: Tetsuya Mukawa > --- > lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 20 +++++++++++++------- > 1 file changed, 13 insertions(+), 7 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 77bb5ed..901f277 100644 > --- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > +++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c > @@ -350,6 +350,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 > */ > @@ -357,7 +362,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 fail0; > } >=20 > /* try mapping somewhere close to the end of hugepages */ @@ -372,14 += 377,9 @@ > pci_uio_map_resource(struct rte_pci_device *dev) > 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; > - Hi Tetsuya, Could close(fd) be called before if(fail) and the following two close(fd) c= alls removed ? Regards, Bernard. > if (fail) { > - rte_free(uio_res); > close(fd); > - return -1; > + goto fail1; > } > close(fd); >=20 > @@ -397,6 +397,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