Thread (10 messages) 10 messages, 3 authors, 2016-07-10
STALE3624d

[PATCH v3] eal/linuxapp: fix resource leak

From: Daniel Mrzyglod <hidden>
Date: 2016-06-22 15:47:19
Subsystem: library code, the rest · Maintainers: Andrew Morton, Linus Torvalds

This patch fix all cases to do proper handle all munmap if pointer
of hugepage is not NULL which prohibits resource leak.

Coverity issue: 97920
Fixes: b6a468ad41d5 ("memory: add --socket-mem option")

Signed-off-by: Daniel Mrzyglod <redacted>
---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 9251a5b..9b0d39a 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1051,7 +1051,7 @@ int
 rte_eal_hugepage_init(void)
 {
 	struct rte_mem_config *mcfg;
-	struct hugepage_file *hugepage, *tmp_hp = NULL;
+	struct hugepage_file *hugepage = NULL, *tmp_hp = NULL;
 	struct hugepage_info used_hp[MAX_HUGEPAGE_SIZES];
 
 	uint64_t memory[RTE_MAX_NUMA_NODES];
@@ -1367,13 +1367,15 @@ rte_eal_hugepage_init(void)
 			"of memory.\n",
 			i, nr_hugefiles, RTE_STR(CONFIG_RTE_MAX_MEMSEG),
 			RTE_MAX_MEMSEG);
-		return -ENOMEM;
+		goto fail;
 	}
 
 	return 0;
 
 fail:
 	free(tmp_hp);
+	if (hugepage != NULL)
+		munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
 	return -1;
 }
 
-- 
2.7.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help