Skip to content

Memory leak when destructing a scoped_interpreter. #1151

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

Closed
tareqsiraj opened this issue Oct 19, 2017 · 2 comments
Closed

Memory leak when destructing a scoped_interpreter. #1151

tareqsiraj opened this issue Oct 19, 2017 · 2 comments

Comments

@tareqsiraj
Copy link

Issue description

Embedding the python interpreter seems to leak memory when compiled with address sanitizer. This happens even with just constructing and destructing a scoped_iterpreter. This seems to happen with both system python2 and python3 libraries.

Environment

g++ (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406

Reproducible example code

//  g++ -std=c++14 -Ipybind11/include -I/usr/include/python3.5m  -fsanitize=address leak.cpp /usr/lib/x86_64-linux-gnu/libpython3.5m.so -o leak && ./leak

#include <pybind11/embed.h>

int main() {
  pybind11::scoped_interpreter _;
  return 0;
}

Expected output

Actual output

=================================================================
==32415==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 385376 byte(s) in 175 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc1af69f  (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0xa169f)

Direct leak of 32704 byte(s) in 146 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc1afd3a in PyDict_New (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0xa1d3a)

Direct leak of 15701 byte(s) in 24 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc1732a7  (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0x652a7)

Direct leak of 12320 byte(s) in 1 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc1af4f9 in _PyDict_NewPresized (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0xa14f9)

Direct leak of 568 byte(s) in 1 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc1736ac  (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0x656ac)

Direct leak of 288 byte(s) in 3 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc1b0044  (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0xa2044)

Direct leak of 224 byte(s) in 1 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc1af5f9 in _PyDict_NewPresized (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0xa15f9)

Direct leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc1b6942 in _PyObjectDict_SetItem (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0xa8942)

Direct leak of 72 byte(s) in 5 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc1ff686 in PyList_New (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0xf1686)

Direct leak of 48 byte(s) in 1 object(s) allocated from:
    #0 0x7ff3dc864270 in __interceptor_realloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc7270)
    #1 0x7ff3dc204564  (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0xf6564)

Direct leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc17efc8 in PyModule_Create2 (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0x70fc8)

Direct leak of 3 byte(s) in 2 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc32c8b1 in PyCode_New (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0x21e8b1)

Direct leak of 2 byte(s) in 2 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc178f64 in PyModule_ExecDef (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0x6af64)

Indirect leak of 42576 byte(s) in 48 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc1732a7  (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0x652a7)

Indirect leak of 2816 byte(s) in 22 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc1b0cba in _PyDict_NewKeysForClass (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0xa2cba)

Indirect leak of 1664 byte(s) in 4 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc1af69f  (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0xa169f)

Indirect leak of 648 byte(s) in 1 object(s) allocated from:
    #0 0x7ff3dc863ec0 in __interceptor_malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc6ec0)
    #1 0x7ff3dc1736ac  (/usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0+0x656ac)

SUMMARY: AddressSanitizer: 495162 byte(s) leaked in 438 allocation(s).
@jagerman
Copy link
Member

This looks rather like an issue in Python itself, e.g. https://bugs.python.org/issue25302 (especially since every leak seems to be coming from libpython3.5m.so rather than your leak binary).

@bstaletic
Copy link
Collaborator

While pybind does have an actual leak (#2024), this doesn't look caused by pybind11.

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

3 participants