From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f50.google.com (mail-pa0-f50.google.com [209.85.220.50]) by dpdk.org (Postfix) with ESMTP id 85E9A58EF for ; Fri, 20 Mar 2015 02:54:43 +0100 (CET) Received: by pagj4 with SMTP id j4so1718065pag.2 for ; Thu, 19 Mar 2015 18:54:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=X64MbHn1bdJu93s+sLurR3gBPXycP4RbAtF2dER+cd8=; b=Dup7qGB2c7v64pIFrZQfrrOOg/O//lUdiKhjwjhbFVYbNDKQW22YPrpN59AQ6y18f8 fqb48aZ6l0i26hrCKxNOasQLQSa/d9bOfuKy9HNkEToGJxenz2c8BMmp2njuJUKL3zQs VQ37Al1K7LPnIcDRjzPiPfHS03xEXdUP/wLKdb3oMRMgRCgurt1PdsiHfzdGBsm+jwbv ZTuEPEBQC7F34DUk7FaEZsFKzucp2PTr5rtYoqt9N67B4r44yk+Y+rZY9WLauN9EScpJ MDeAF74MktwKBjcrgahtIm3DVy37egq1CObodcTf9i9+0dXx8vJyfKdwXT+dNcwpghSE Uq8g== X-Gm-Message-State: ALoCoQnFdllkLQcWgZKeho/Xd+5figFiPSFZ4gjSi6Rkm5dPX1VsePXruIHss30+/jWKvp1QaSS9 X-Received: by 10.66.234.2 with SMTP id ua2mr160130000pac.137.1426816482849; Thu, 19 Mar 2015 18:54:42 -0700 (PDT) Received: from [10.16.129.101] (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id ce1sm5136952pdb.34.2015.03.19.18.54.41 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 18:54:42 -0700 (PDT) Message-ID: <550B7DE4.9010309@igel.co.jp> Date: Fri, 20 Mar 2015 10:54:44 +0900 From: Tetsuya Mukawa User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: "Iremonger, Bernard" , "dev@dpdk.org" 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> In-Reply-To: <8CEF83825BEC744B83065625E567D7C2049F3B77@IRSMSX108.ger.corp.intel.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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: Fri, 20 Mar 2015 01:54:44 -0000 On 2015/03/20 1:20, Iremonger, Bernard wrote: > >> -----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 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