DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] array malloced by backtrace_symbols() should be freed by the caller
@ 2015-08-04  9:04 chixiaobo
  2015-08-04 16:12 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: chixiaobo @ 2015-08-04  9:04 UTC (permalink / raw)
  To: dev; +Cc: chixiaobo

As to  linux man page: http://linux.die.net/man/3/backtrace_symbols, The address of the array of string pointers is returned as the function result of backtrace_symbols(). This array is malloced by backtrace_symbols(), and must be freed by the caller. The strings pointed to by the array of pointers need not and should not be freed.

Signed-off-by: chixiaobo <xiaobo.chi@nokia.com>
---
 lib/librte_eal/bsdapp/eal/eal_debug.c   | 3 +++
 lib/librte_eal/linuxapp/eal/eal_debug.c | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/eal_debug.c b/lib/librte_eal/bsdapp/eal/eal_debug.c
index 44fc4f3..ceca2e8 100644
--- a/lib/librte_eal/bsdapp/eal/eal_debug.c
+++ b/lib/librte_eal/bsdapp/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 );
 }
 
 /* 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..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 );
 }
 
 /* not implemented in this environment */
-- 
1.9.4.msysgit.2

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dpdk-dev] [PATCH] array malloced by backtrace_symbols() should be freed by the caller
  2015-08-04  9:04 [dpdk-dev] [PATCH] array malloced by backtrace_symbols() should be freed by the caller chixiaobo
@ 2015-08-04 16:12 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2015-08-04 16:12 UTC (permalink / raw)
  To: chixiaobo; +Cc: dev

On Tue,  4 Aug 2015 17:04:18 +0800
chixiaobo <xiaobo.chi@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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-08-04 16:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-04  9:04 [dpdk-dev] [PATCH] array malloced by backtrace_symbols() should be freed by the caller chixiaobo
2015-08-04 16:12 ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).