This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Memory Leaks with Address Sanitizer
Type: resource usage Stage: resolved
Components: Interpreter Core Versions: Python 3.4
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: Matt Clarkson, skrah, vstinner
Priority: normal Keywords:

Created on 2015-10-02 16:04 by Matt Clarkson, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
leak.log Matt Clarkson, 2015-10-02 16:04 The stack trace of the leaks
Messages (2)
msg252136 - (view) Author: Matt Clarkson (Matt Clarkson) Date: 2015-10-02 16:04
I have the following `main.cpp`

```
#include <Python.h>

int main() {
  Py_Initialize();

  if (!Py_IsInitialized())
    return 1;

  Py_Finalize();

  return 0;
}
```

Compiled with on Arch Linux 4.2.1 gcc 5.2.0 python 3.4.3:

```
g++ -fsanitize=address main.cpp -o main `python-config --includes --ldflags
```

I end up with 424764 byte(s) leaked in 316 allocation(s).

I can suppress the leaks in the following ways:

```
# These are the high level functions that leak (i.e. the *top* of the call stack)
#leak:Py_Initialize
#leak:Py_Finalize
#leak:PyEval_EvalCode

# Low level private functions that leak (i.e. the *bottom* of the call stack)
leak:new_keys_object
leak:type_new
leak:new_dict_with_shared_keys
leak:make_keys_shared
leak:_PyObject_Malloc
leak:PyList_New

# The closest to the leak public functions (i.e. closest to the *top* of the call stack)
#leak:PyUnicode_New
#leak:PyList_New
#leak:PyFrame_New
#leak:PyDict_New
#leak:PyBytes_FromStringAndSize
#leak:PyObject_Call
#leak:PyType_Ready
#leak:PyDict_Merge
#leak:PyDict_SetItemString
#leak:PyEval_EvalFrameEx
```

I read in the `PyInitalize` documentation that circular references, etc might not be freed but 424764 bytes seems a lot just for initializing the Python engine.

I would like to help out solving the memory leaks, if that is possible?
msg252207 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-10-03 12:19
Static types leak memory on finalization, see PEP 3121. Normally it
does not matter, but you see it when embedding Python.

PEP 3121 isn't widely implemented because a) it complicates the
code for large modules and b) there are some performance issues.


There are several other open issues for the problem, so I'm closing
this one.
History
Date User Action Args
2022-04-11 14:58:22adminsetgithub: 69489
2015-10-03 12:19:59skrahsetstatus: open -> closed

nosy: + skrah
messages: + msg252207

resolution: duplicate
stage: resolved
2015-10-02 16:11:01vstinnersetnosy: + vstinner
2015-10-02 16:04:25Matt Clarksoncreate