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

LEAK (C++ exception in app built w/ mingw g++ 4.5.2) #1043

Closed
derekbruening opened this issue Nov 28, 2014 · 6 comments
Closed

LEAK (C++ exception in app built w/ mingw g++ 4.5.2) #1043

derekbruening opened this issue Nov 28, 2014 · 6 comments

Comments

@derekbruening
Copy link
Contributor

From bruen...@google.com on October 08, 2012 09:04:56

i686-pc-mingw32-g++.exe -static-libgcc -static-libstdc++ -ggdb -o cs2bug-mingw-4.5.2.exe cs2bug.cpp

~/drmemory/git/build_x86_dbg/bin/drmemory.exe -dr d:/derek/dr/git/exports -batch -- ./cs2bug-mingw-4.5.2.exe

in addition to the expected errors we have:

Error #8: UNADDRESSABLE ACCESS: reading 0x7efdde1c-0x7efdde20 4 byte(s)
=> issue #623 Error #10: LEAK 8 direct bytes 0x00d1d078-0x00d1d080 + 0 indirect bytes
#0 __cxa_get_globals [/usr/src/packages/mingw-gcc/mingw-gcc-4.5.2-1/src/gcc-4.5.2/libstdc++-v3/libsupc++/eh_globals.cc:132]
#1 __cxa_allocate_exception [/usr/src/packages/mingw-gcc/mingw-gcc-4.5.2-1/src/gcc-4.5.2/libstdc++-v3/libsupc++/eh_alloc.cc:132]
#2 test_exception() [/d/derek/dr/test/cs2bug.cpp:165]
#3 main [/d/derek/dr/test/cs2bug.cpp:206]

Original issue: http://code.google.com/p/drmemory/issues/detail?id=1043

@derekbruening
Copy link
Contributor Author

From bruen...@google.com on February 20, 2013 11:38:26

xref issue #1134 xref the leak mentioned here, in gcc's libgcc/config/i386/gthr-win32.c,
though the leak for this issue is still there with -mthreads:

  1. The destructor supplied to __gthread_key_create is ignored for
    generic x86-win32 ports. This will certainly cause memory leaks
    due to unreclaimed eh contexts (sizeof (eh_context) is at least
    24 bytes for x86 currently).

    This memory leak may be significant for long-running applications
    that make heavy use of C++ EH.

    However, Mingw runtime (version 0.3 or newer) provides a mechanism
    to emulate pthreads key dtors; the runtime provides a special DLL,
    linked in if -mthreads option is specified, that runs the dtors in
    the reverse order of registration when each thread exits. If
    -mthreads option is not given, a stub is linked in instead of the
    DLL, which results in memory leak. Other x86-win32 ports can use
    the same technique of course to avoid the leak.

@derekbruening
Copy link
Contributor Author

From bruen...@google.com on February 20, 2013 11:46:31

although I have not taken the time to prove it, most likely this is a real leak so I'm going to add a suppression

Labels: -Bug-FalsePositive ThirdParty-Bug

@derekbruening
Copy link
Contributor Author

From bruen...@google.com on February 20, 2013 11:48:34

for the record, this shows up on the test app listed in issue #1134

@derekbruening
Copy link
Contributor Author

From bruen...@google.com on February 20, 2013 11:54:21

Actually, the reason the mingw key dtors aren't freeing the memory may be
due to the issue #1134 bug.
from mingw's src/libcrt/crt/tlsthrd.c:
LPVOID value = TlsGetValue (keyp->key);
if (GetLastError () == ERROR_SUCCESS)
{
if (value)
(*keyp->dtor) (value);
}

TlsGetValue() will fail b/c TlsFree was already called (that's the issue #1134 bug) and thus the destructor won't be called, at least from looking at the
code.

@derekbruening
Copy link
Contributor Author

From bruen...@google.com on February 20, 2013 13:08:30

filed as https://sourceforge.net/p/mingw/bugs/1928/

@derekbruening
Copy link
Contributor Author

From derek.br...@gmail.com on February 21, 2013 13:42:50

This issue was closed by revision r1190 .

Status: Fixed

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

No branches or pull requests

1 participant