[dpdk-dev] [PATCH] array malloced by backtrace_symbols() should be freed by the caller

Stephen Hemminger stephen at networkplumber.org
Tue Aug 4 18:12:23 CEST 2015

On Tue,  4 Aug 2015 17:04:18 +0800
chixiaobo <xiaobo.chi at nokia.com> wrote:

> diff --git a/lib/librte_eal/linuxapp/eal/eal_debug.c b/lib/librte_eal/linuxapp/eal/eal_debug.c
> index 44fc4f3..ceca2e8 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_debug.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_debug.c
> @@ -58,6 +58,9 @@ void rte_dump_stack(void)
>  			"%d: [%s]\n", size, symb[size - 1]);
>  		size --;
>  	}
> +	/* This array is malloced by backtrace_symbols(), and must be freed by the caller */
> +	if( symb )
> +		free( (void *)symb );

I agree that free() should probably be done, but am a little worried
that it just make things break. Since lots of times when this code is called
the malloc pool is in broken state because the whole reason for calling backtrace
is to handle panic situation.

Please use the standard white space style, and do not add a cast to void *
where none is required in C.

On a related note, I found that backtrace_symbols was rather poor at decoding
and finding many symbols. The unwind library does a better job.

More information about the dev mailing list