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

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

Commit Message

Daniel Mrzyglod July 6, 2016, 10:44 a.m. UTC
  Current code does not munmap 'hugepage' mapping (hugepage info file) on
function exit, leaking resources.

Coverity issue: 97920
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 | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
  

Comments

Sergio Gonzalez Monroy July 6, 2016, 10:48 a.m. UTC | #1
On 06/07/2016 11:44, Daniel Mrzyglod wrote:
> Current code does not munmap 'hugepage' mapping (hugepage info file) on
> function exit, leaking resources.
>
> Coverity issue: 97920
> Fixes: b6a468ad41d5 ("memory: add --socket-mem option")
>
> Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
> ---

Please next time remember to keep patch version history after the triple 
dashes.

Acked-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>
  
Thomas Monjalon July 10, 2016, 1:29 p.m. UTC | #2
2016-07-06 11:48, Sergio Gonzalez Monroy:
> On 06/07/2016 11:44, Daniel Mrzyglod wrote:
> > Current code does not munmap 'hugepage' mapping (hugepage info file) on
> > function exit, leaking resources.
> >
> > Coverity issue: 97920
> > Fixes: b6a468ad41d5 ("memory: add --socket-mem option")
> >
> > Signed-off-by: Daniel Mrzyglod <danielx.t.mrzyglod@intel.com>
> > ---
> 
> Please next time remember to keep patch version history after the triple 
> dashes.
> 
> Acked-by: Sergio Gonzalez Monroy <sergio.gonzalez.monroy@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c
index 5578c25..b663244 100644
--- a/lib/librte_eal/linuxapp/eal/eal_memory.c
+++ b/lib/librte_eal/linuxapp/eal/eal_memory.c
@@ -1136,7 +1136,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];
@@ -1479,14 +1479,19 @@  rte_eal_hugepage_init(void)
 			"of memory.\n",
 			i, nr_hugefiles, RTE_STR(CONFIG_RTE_MAX_MEMSEG),
 			RTE_MAX_MEMSEG);
-		return -ENOMEM;
+		goto fail;
 	}
 
+	munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
+
 	return 0;
 
 fail:
 	huge_recover_sigbus();
 	free(tmp_hp);
+	if (hugepage != NULL)
+		munmap(hugepage, nr_hugefiles * sizeof(struct hugepage_file));
+
 	return -1;
 }