From faefe2296da86bb95ffbb5a8925b026dc006744c Mon Sep 17 00:00:00 2001 From: Zhe Tao Date: Mon, 21 Sep 2015 17:00:47 +0800 Subject: [PATCH] eal: fix memory leak in stack dump Free the memory allocated by the backtrace_symbols to prevent the memory leak. Signed-off-by: Zhe Tao --- lib/librte_eal/bsdapp/eal/eal_debug.c | 6 ++++++ lib/librte_eal/linuxapp/eal/eal_debug.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/lib/librte_eal/bsdapp/eal/eal_debug.c b/lib/librte_eal/bsdapp/eal/eal_debug.c index 44fc4f338b..907fbfa7b8 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 (symb == NULL) + 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 44fc4f338b..907fbfa7b8 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 (symb == NULL) + 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 */ -- 2.20.1