[dpdk-dev,v2] eal/linuxapp: fix resource leak

Message ID 1463044364-132623-1-git-send-email-danielx.t.mrzyglod@intel.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers

Commit Message

Daniel Mrzyglod May 12, 2016, 9:12 a.m. UTC
  Fix issue reported by Coverity.
Coverity ID 97920

munmap structure of hugepage

leaked_storage: Variable hugepage going out of scope leaks the storage
it points to.

The system resource will not be reclaimed and reused, reducing the future
availability of the resource.

In rte_eal_hugepage_init: Leak of memory or pointers to system resources

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

Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
---
 lib/librte_eal/linuxapp/eal/eal_memory.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
  

Comments

Thomas Monjalon June 20, 2016, 9:33 a.m. UTC | #1
2016-05-12 11:12, Daniel Mrzyglod:
> Fix issue reported by Coverity.
> Coverity ID 97920
> 
> munmap structure of hugepage
> 
> leaked_storage: Variable hugepage going out of scope leaks the storage
> it points to.
> 
> The system resource will not be reclaimed and reused, reducing the future
> availability of the resource.
> 
> In rte_eal_hugepage_init: Leak of memory or pointers to system resources

Please reword.
  

Patch

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 5b9132c..9fd0d8d 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;
 }