boostorg / stacktrace

C++ library for storing and printing backtraces.
https://boost.org/libs/stacktrace
422 stars 70 forks source link

memory leak #111

Closed ycyclop closed 6 months ago

ycyclop commented 3 years ago

When I do a simple stacktrace there is a memory leak that I do not expect:

int main()
{
    int counter = 0;
    while (counter < 1000)
    {
        std::cout << boost::stacktrace::stacktrace();
        counter++;
    }
}

in debug the application starts with a footprint of ~40k, at the end it raises to ~440k and as you can see all it does is call the stacktrace(). In my full application I fear it has some other impact on the memory like corruption that causes the application to misbehave after ~1000 calls but I didn't manage to reproduce it in a smaller scale. The issue I encountered is eliminated when I remove this call std::cout << boost::stacktrace::stacktrace(); in my real application.

This is on a MSVC 2019 environment. toolset v142

correa commented 2 years ago

We have also found this issue on MSVC 2019 with Boost 1.72.0

correa commented 2 years ago

Tested with Boost 1.77.0 and the leak still happens. If BOOST_STACKTRACE_USE_WINDBG_CACHED is defined then process memory usage remains stable (and the code runs much faster).

apolukhin commented 6 months ago

Fixed in 27093f24cb2ff187b179ffc561bdf0c27d7cf551 and https://github.com/boostorg/stacktrace/commit/f783534b0f22379e39597cf380f01e7199c24c29

Will update the docs soon