From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f54.google.com (mail-pa0-f54.google.com [209.85.220.54]) by dpdk.org (Postfix) with ESMTP id A94869AA8 for ; Tue, 17 Mar 2015 10:31:11 +0100 (CET) Received: by padcy3 with SMTP id cy3so4628702pad.3 for ; Tue, 17 Mar 2015 02:31:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QUly9WquiFn1fJX89iQ9YLhaGah7gl/aQe6YR4IhZ68=; b=Ev5WUtiqO3yIdelDANDepBOtlyapPv0IitCZ+iwJfd7KpzXzW5PQIYbbhzQPdVE58P 5c5yABrXOkY8j/HSdbqiCuNAzxhwmqgrLpfWxjN7C1OjOZeoxVtYaoSBuVSM1ehCM7Y1 Qc4I32NKjcQ4IrrlfglX5QDhEC1M+rdLPE00u5aRunGgF3YfMcZxUG8GEP7J/6ki2wIp kk7LAkJj8nHQqi2VGZs0HnA7POkpFAovy8+gcKVL9OuBW6SCirs93B9DuQU1YMTbcZkd fgERR7A3lgoi899c1mPGPVEvo7EQ44hG32woR/3W04/rQEMN9KPeudPCRILwXi3VXqmW ZiJA== X-Gm-Message-State: ALoCoQkV4I2Fw23/0sHRQ9mEJUXEoXv48akImM8VcYnguKVDz3t1lCZFZqlrtxalgDnUi34wJy6L X-Received: by 10.70.118.197 with SMTP id ko5mr55037365pdb.137.1426584671071; Tue, 17 Mar 2015 02:31:11 -0700 (PDT) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id ce1sm21354243pdb.34.2015.03.17.02.31.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Mar 2015 02:31:10 -0700 (PDT) From: Tetsuya Mukawa To: dev@dpdk.org Date: Tue, 17 Mar 2015 18:30:42 +0900 Message-Id: <1426584645-28828-4-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426584645-28828-1-git-send-email-mukawa@igel.co.jp> References: <1426155474-1596-4-git-send-email-mukawa@igel.co.jp> <1426584645-28828-1-git-send-email-mukawa@igel.co.jp> Subject: [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: Tue, 17 Mar 2015 09:31:12 -0000 When pci_map_resource() is failed but path is allocated correctly, path 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. - 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_eal/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 = uio_res->maps; for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) { int fd; - int fail = 0; /* skip empty BAR */ phaddr = 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 = rte_malloc(NULL, strlen(devname) + 1, 0); + if (maps[map_idx].path == 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,23 +367,13 @@ pci_uio_map_resource(struct rte_pci_device *dev) mapaddr = pci_map_resource(pci_map_addr, fd, 0, (size_t)dev->mem_resource[i].len, 0); + close(fd); if (mapaddr == MAP_FAILED) - fail = 1; + goto fail1; pci_map_addr = RTE_PTR_ADD(mapaddr, (size_t)dev->mem_resource[i].len); - maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0); - if (maps[map_idx].path == NULL) - fail = 1; - - if (fail) { - rte_free(uio_res); - close(fd); - return -1; - } - close(fd); - maps[map_idx].phaddr = dev->mem_resource[i].phys_addr; maps[map_idx].size = dev->mem_resource[i].len; maps[map_idx].addr = 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