Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using bytehound with MEMORY_PROFILER_USE_SHADOW_STACK=1 does not destroy exception objects properly #119

Open
radx64 opened this issue Nov 17, 2023 · 0 comments

Comments

@radx64
Copy link

radx64 commented Nov 17, 2023

Hi,
Great tool!
During some profiling I've encountered very interesting leak which targets exception handling.

Seems that bytehound stack fast unwind algorithm omits destructors in exception objects marking them as leaky.

bytehound version: 0.11.0

MEMORY_PROFILER_USE_SHADOW_STACK=1 is default setting

Small example with simple test program:

#include <stdexcept>
#include <iostream>


void preconfigure()
{
     throw std::runtime_error("some_random_exception");
}

void handle()
{
    try
    {
        preconfigure();
    }
    catch(const std::exception& e)
    {
        return;   
    }
}

int main(int argc, char** argv)
{
    for (int i=0; i<1000; ++i)
    {
        handle();
    }
    return 0;
}

build with g++ (ver 11.4.0) with no extra flags and run with bytehound.so lib

g++ main.cpp
LD_PRELOAD=./libbytehound.so ./a.out

leaks

running same binary (not recompiled) with:

MEMORY_PROFILER_USE_SHADOW_STACK=0 LD_PRELOAD=./libbytehound.so ./a.out

shows no leaks
no_leaks

The only difference is using shadow stack configuration parameter.

When I've tested calling the destructor of exception seems that it is not even called when shadow stack is used (so this is a real leak, but somehow caused by bytehound itself)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant