-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
python3.12 introduces numerous memory leaks (as reported by ASAN) #113190
Comments
I assume those are various „global” objects and to a degree the report is spurious, nevertheless using sanitizer while maintaining binary python extensions and code embedding python turned out to be invaluable for me many times (esp. considering new/borrow reference semantics is often poorly documented and related code error-prone). On py3.10 I had nice, clear state, on py3.12 the same code reports plenty of leaks. Example above is only a start, slightly more complicated code (clear and sane on 3.10) starts reporting much more leaks, mostly mentioning Tested on python 3.12.1 from deadsnakes. |
Maybe one more example:
|
Staying in stdlib:
|
I can't comment about reasons, but the bug you mention claims that some leak existed, and 3.12 only increased it's scale in case multiple interpreters are in use ( #113055 (comment) ). In my case (a) there is single interpreter in use and (b) 3.10 and 3.11 don't report any leaks (neither in simple examples above, nor in more complicated real code). |
Valgrind doesn't see any leak in the current 3.12 branch:
valgrind.log:
I'm not sure why this traceback is truncated, but without a more complete traceback, I don't see how to debug this issue. |
It's possible to build Python with
The problem is that all dependencies of Python, such as OpenSSL, should be built with the same option. Otherwise, clang can emit false alarms. Example in OpenSSL:
Right now on my Fedora 39, even with
|
In case it is helpful at all I can replicate the issue with a slightly more complete traceback from 3.12.4: Direct leak of 111239 byte(s) in 2183 object(s) allocated from:
#0 0x73eaeb6b4887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
#1 0x5f50f90dc618 in PyObject_Malloc /usr/local/src/conda/python-3.12.4/Objects/obmalloc.c:801
#2 0x5f50f90dc618 in PyUnicode_New /usr/local/src/conda/python-3.12.4/Objects/unicodeobject.c:1251
#3 0x5f50f90dc618 in _PyUnicode_FromUCS1 /usr/local/src/conda/python-3.12.4/Objects/unicodeobject.c:2036
#4 0x5f50f90dc618 in _PyUnicode_FromUCS1 /usr/local/src/conda/python-3.12.4/Objects/unicodeobject.c:2022
Direct leak of 58060 byte(s) in 1111 object(s) allocated from:
#0 0x73eaeb6b4887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
#1 0x5f50f90c419b in PyObject_Malloc /usr/local/src/conda/python-3.12.4/Objects/obmalloc.c:801
#2 0x5f50f90c419b in PyUnicode_New /usr/local/src/conda/python-3.12.4/Objects/unicodeobject.c:1251
#3 0x5f50f90c419b in unicode_decode_utf8 /usr/local/src/conda/python-3.12.4/Objects/unicodeobject.c:4693
Direct leak of 459 byte(s) in 7 object(s) allocated from:
#0 0x73eaeb6b4887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
#1 0x5f50f911318a in PyObject_Malloc /usr/local/src/conda/python-3.12.4/Objects/obmalloc.c:801
#2 0x5f50f911318a in PyUnicode_New /usr/local/src/conda/python-3.12.4/Objects/unicodeobject.c:1251
#3 0x5f50f911318a in _PyUnicode_JoinArray /usr/local/src/conda/python-3.12.4/Objects/unicodeobject.c:9661
Direct leak of 50 byte(s) in 1 object(s) allocated from:
#0 0x73eaeb6b4887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
#1 0x5f50f90d1da1 in PyObject_Malloc /usr/local/src/conda/python-3.12.4/Objects/obmalloc.c:801
#2 0x5f50f90d1da1 in PyUnicode_New /usr/local/src/conda/python-3.12.4/Objects/unicodeobject.c:1251
#3 0x5f50f90d1da1 in _PyUnicode_FromASCII /usr/local/src/conda/python-3.12.4/Objects/unicodeobject.c:1998
|
Bug report
Bug description:
Let example illustrate:
CPython versions tested on:
3.12.1
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: