From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tetsuya Mukawa Subject: Re: [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation Date: Fri, 20 Mar 2015 10:54:44 +0900 Message-ID: <550B7DE4.9010309@igel.co.jp> 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> <8CEF83825BEC744B83065625E567D7C2049F3B77@IRSMSX108.ger.corp.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable To: "Iremonger, Bernard" , "dev-VfR2kkLFssw@public.gmane.org" Return-path: In-Reply-To: <8CEF83825BEC744B83065625E567D7C2049F3B77-kPTMFJFq+rEMvF1YICWikbfspsVTdybXVpNB7YpNyf8@public.gmane.org> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces-VfR2kkLFssw@public.gmane.org Sender: "dev" On 2015/03/20 1:20, Iremonger, Bernard wrote: > >> -----Original Message----- >> From: Tetsuya Mukawa [mailto:mukawa-AlSX/UN32fvPDbFq/vQRIQ@public.gmane.org] >> Sent: Tuesday, March 17, 2015 9:31 AM >> To: dev-VfR2kkLFssw@public.gmane.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 implem= entation" to "needless increment of pci_map_addr" in commit line. > >> When pci_map_resource() is failed but path is allocated correctly, pat= h won'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. >> >> Also, the patch fixes belows. > Typo "belows" should be "below". Hi Bernard, I appreciate for your checking. I will fix it. Regards, Tetsuya > Regards, > > Bernard. > >> - To shrink code, move close(). >> - Remove fail variable. >> >> Signed-off-by: Tetsuya Mukawa >> --- >> lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 28 ++++++++++++++--------= ------ >> 1 file changed, 14 insertions(+), 14 deletions(-) >> >> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_ea= l/linuxapp/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; >> >> /* 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); >> >> + /* 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; >> } >> >> /* try mapping somewhere close to the end of hugepages */ @@ -363,2= 3 +367,13 @@ >> pci_uio_map_resource(struct rte_pci_device *dev) >> >> 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; >> >> pci_map_addr =3D RTE_PTR_ADD(mapaddr, >> (size_t)dev->mem_resource[i].len); >> >> - 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); >> >> return 0; >> + >> +fail1: >> + rte_free(maps[map_idx].path); >> +fail0: >> + rte_free(uio_res); >> + return -1; >> } >> >> #ifdef RTE_LIBRTE_EAL_HOTPLUG >> -- >> 1.9.1