DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/1] lib/librte_eal: fix resource leak
@ 2016-04-19 16:27 Marcin Kerlin
  2016-04-20  9:15 ` David Marchand
  2016-06-14 15:33 ` [dpdk-dev] [PATCH v2 1/1] eal: fix resource leak of mapped memory Marcin Kerlin
  0 siblings, 2 replies; 15+ messages in thread
From: Marcin Kerlin @ 2016-04-19 16:27 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Marcin Kerlin

Fix issue reported by Coverity.

Coverity ID 13295, 13296, 13303:
Resource leak: The system resource will not be reclaimed
and reused, reducing the future availability of the resource.
In rte_eal_hugepage_attach: Leak of memory or pointers to system
resources.

Fixes: af75078fece3 ("first public release")

Signed-off-by: Marcin Kerlin <marcinx.kerlin@intel.com>
---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 5b9132c..6320aa0 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1475,13 +1475,17 @@ rte_eal_hugepage_attach(void)
 					"and retry running both primary "
 					"and secondary processes\n");
 			}
+
+			if (base_addr != MAP_FAILED)
+				munmap((void *)(uintptr_t)base_addr, mcfg->memseg[s].len);
+
 			goto error;
 		}
 	}
 
 	size = getFileSize(fd_hugepage);
 	hp = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd_hugepage, 0);
-	if (hp == NULL) {
+	if (hp == MAP_FAILED) {
 		RTE_LOG(ERR, EAL, "Could not mmap %s\n", eal_hugepage_info_path());
 		goto error;
 	}
@@ -1535,6 +1539,10 @@ rte_eal_hugepage_attach(void)
 						addr != RTE_PTR_ADD(base_addr, offset)) {
 					RTE_LOG(ERR, EAL, "Could not mmap %s\n",
 						hp[i].filepath);
+
+					if (addr != MAP_FAILED)
+						munmap((void *)(uintptr_t)addr, mapping_size);
+
 					goto error;
 				}
 				offset+=mapping_size;
@@ -1551,6 +1559,8 @@ rte_eal_hugepage_attach(void)
 	return 0;
 
 error:
+	if (hp != NULL && hp != MAP_FAILED)
+		munmap((void *) (uintptr_t) hp, size);
 	if (fd_zero >= 0)
 		close(fd_zero);
 	if (fd_hugepage >= 0)
-- 
1.9.1

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2016-06-20  9:30 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-19 16:27 [dpdk-dev] [PATCH 1/1] lib/librte_eal: fix resource leak Marcin Kerlin
2016-04-20  9:15 ` David Marchand
2016-04-21 11:19   ` Sergio Gonzalez Monroy
2016-04-21 11:49     ` Kerlin, MarcinX
2016-04-22 10:42     ` Panu Matilainen
2016-06-14 15:33 ` [dpdk-dev] [PATCH v2 1/1] eal: fix resource leak of mapped memory Marcin Kerlin
2016-06-15  8:49   ` Sergio Gonzalez Monroy
2016-06-15  9:35     ` Kerlin, MarcinX
2016-06-15 10:05       ` Panu Matilainen
2016-06-15 11:13         ` Kerlin, MarcinX
2016-06-15 10:45   ` [dpdk-dev] [PATCH v3 " Marcin Kerlin
2016-06-15 12:25     ` [dpdk-dev] [PATCH v4 " Marcin Kerlin
2016-06-16 12:57       ` Sergio Gonzalez Monroy
2016-06-16 15:14       ` [dpdk-dev] [PATCH v5 " Marcin Kerlin
2016-06-20  9:30         ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).