[dpdk-dev] [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource()
Tetsuya Mukawa
mukawa at igel.co.jp
Thu Mar 12 11:17:42 CET 2015
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.
Signed-off-by: Tetsuya Mukawa <mukawa at igel.co.jp>
---
lib/librte_eal/linuxapp/eal/eal_pci_uio.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/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);
+ /* 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
*/
@@ -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;
}
/* 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 = 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;
+ goto fail1;
}
close(fd);
@@ -397,6 +397,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
More information about the dev
mailing list