Memory leak due to calling `backtrace_create_state` multiple times
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.
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
Should that be static and not ststic here?
https://github.com/boostorg/stacktrace/commit/308b7f6b087a302795d6a189373f254f610a826f#diff-1f3dccb3928ad7b52e4c986270cb619b663197283b764c2fb68256d285f21a3fR124
Oops, thanks!