stacktrace icon indicating copy to clipboard operation
stacktrace copied to clipboard

Memory leak due to calling `backtrace_create_state` multiple times

Open Cogitri opened this issue 4 years ago • 1 comments

Hello,

currently boost-stacktrace with the backtrace backend will call backtrace_create_state once for each thread. This creates a memory leak since each time a new thread is created, a new backtrace_state is allocated but it's never freed (and can't be since there's no backtrace_destroy_state). See e.g. https://patchwork.ozlabs.org/project/gcc/patch/[email protected]/#1625428 for more discussion on this.

Cogitri avatar Jan 12 '22 09:01 Cogitri

Unfortunately, it's not a bug but a feature:

https://github.com/boostorg/stacktrace/blob/08d720adbd01c0187af256eb491cffece7e87857/include/boost/stacktrace/detail/libbacktrace_impls.hpp#L74-L85

There's some issue either with the packaged versions of libbacktrace, or some issue in the libbacktrace with some compiler flags that I failed to localize https://gcc.gnu.org/bugzilla//show_bug.cgi?id=87653

I have to add more docs and references into the sources and provide a macro to force single instance for those' who wish to take the risk

apolukhin avatar Sep 01 '22 15:09 apolukhin

Should that be static and not ststic here? https://github.com/boostorg/stacktrace/commit/308b7f6b087a302795d6a189373f254f610a826f#diff-1f3dccb3928ad7b52e4c986270cb619b663197283b764c2fb68256d285f21a3fR124

pergraa-celonis avatar Nov 15 '22 10:11 pergraa-celonis

Oops, thanks!

apolukhin avatar Jan 18 '23 14:01 apolukhin