[dpdk-dev] eal: change to prevent memory leak in eal debug

Message ID 1442826047-4093-1-git-send-email-zhe.tao@intel.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Zhe Tao Sept. 21, 2015, 9 a.m. UTC
  Free the memory allocated by the backtrace_symbols
 to prevent the memory leak

Signed-off-by: Zhe Tao <zhe.tao@intel.com>
---
 lib/librte_eal/bsdapp/eal/eal_debug.c   | 6 ++++++
 lib/librte_eal/linuxapp/eal/eal_debug.c | 6 ++++++
 2 files changed, 12 insertions(+)
  

Comments

Thomas Monjalon Oct. 25, 2015, 10:41 p.m. UTC | #1
2015-09-21 17:00, Zhe Tao:
> Free the memory allocated by the backtrace_symbols
>  to prevent the memory leak
> 
> Signed-off-by: Zhe Tao <zhe.tao@intel.com>

Applied, with reverted comparisons:

WARNING:CONSTANT_COMPARISON: Comparisons should place the constant on the right side of the test
+       if (NULL == symb)
  

Patch

diff --git a/lib/librte_eal/bsdapp/eal/eal_debug.c b/lib/librte_eal/bsdapp/eal/eal_debug.c
index 44fc4f3..82d1c81 100644
--- a/lib/librte_eal/bsdapp/eal/eal_debug.c
+++ b/lib/librte_eal/bsdapp/eal/eal_debug.c
@@ -53,11 +53,17 @@  void rte_dump_stack(void)
 
 	size = backtrace(func, BACKTRACE_SIZE);
 	symb = backtrace_symbols(func, size);
+
+	if (NULL == symb)
+		return;
+
 	while (size > 0) {
 		rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL,
 			"%d: [%s]\n", size, symb[size - 1]);
 		size --;
 	}
+
+	free(symb);
 }
 
 /* not implemented in this environment */
diff --git a/lib/librte_eal/linuxapp/eal/eal_debug.c b/lib/librte_eal/linuxapp/eal/eal_debug.c
index 44fc4f3..82d1c81 100644
--- a/lib/librte_eal/linuxapp/eal/eal_debug.c
+++ b/lib/librte_eal/linuxapp/eal/eal_debug.c
@@ -53,11 +53,17 @@  void rte_dump_stack(void)
 
 	size = backtrace(func, BACKTRACE_SIZE);
 	symb = backtrace_symbols(func, size);
+
+	if (NULL == symb)
+		return;
+
 	while (size > 0) {
 		rte_log(RTE_LOG_ERR, RTE_LOGTYPE_EAL,
 			"%d: [%s]\n", size, symb[size - 1]);
 		size --;
 	}
+
+	free(symb);
 }
 
 /* not implemented in this environment */