New submission from Boris Staletic <boris.stale...@gmail.com>:

The following C code leaks 7 locks allocated with PyThread_allocate_lock:

#include <Python.h>

int main()
{
        Py_Initialize();
        PyObject* multiprocessing = PyImport_ImportModule("multiprocessing");
        PyObject* Process = PyObject_GetAttrString(multiprocessing, "Process");
        PyObject* args = PyTuple_New(0);
        PyObject* kw = PyDict_New();
        PyDict_SetItemString(kw, "target", Process);

        PyObject* p = PyObject_Call(Process, args, kw);
        PyObject* start = PyObject_GetAttrString(p, "start");
        PyObject* join = PyObject_GetAttrString(p, "join");

        PyObject_CallNoArgs(start);
        PyObject_CallNoArgs(join);

        Py_DECREF(join);
        Py_DECREF(start);
        Py_DECREF(p);
        Py_DECREF(kw);
        Py_DECREF(args);
        Py_DECREF(Process);
        Py_DECREF(multiprocessing);
        Py_Finalize();
}



The following locks are leaked:

1. 
https://github.com/python/cpython/blob/196d4deaf4810a0bba75ba537dd40f2d71a5a634/Python/pystate.c#L78
2. 
https://github.com/python/cpython/blob/196d4deaf4810a0bba75ba537dd40f2d71a5a634/Python/pystate.c#L84
3. 
https://github.com/python/cpython/blob/196d4deaf4810a0bba75ba537dd40f2d71a5a634/Python/pystate.c#L90
4. https://github.com/python/cpython/blob/master/Python/ceval.c#L810
5. https://github.com/python/cpython/blob/master/Python/import.c#L126
6. and 7. 
https://github.com/python/cpython/blob/master/Modules/_threadmodule.c#L597

In the attachment is valgrind's output.

----------
components: C API
files: log
messages: 386558
nosy: bstaletic
priority: normal
severity: normal
status: open
title: Leak of locks in a subprocess
type: resource usage
versions: Python 3.10, Python 3.9
Added file: https://bugs.python.org/file49793/log

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43145>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to