classification
Title: Leak in tstate->interp->ceval.pending
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: skrah, vstinner
Priority: normal Keywords: patch

Created on 2020-04-08 12:19 by skrah, last changed 2020-04-08 15:55 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19436 merged vstinner, 2020-04-08 15:27
Messages (4)
msg365980 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2020-04-08 12:19
50e6e991781db761c496561a995541ca8d83ff87 causes or exposes a
leak. Possibly the leak was there before but showed up under
"still reachable".

Now it is "definitely lost", so tstate->interp->ceval.pending
needs to be cleaned up.


==11235== 32 bytes in 1 blocks are definitely lost in loss record 186 of 1,901
==11235==    at 0x483880B: malloc (vg_replace_malloc.c:309)
==11235==    by 0x467061: _PyMem_RawMalloc (obmalloc.c:99)
==11235==    by 0x467A24: PyMem_RawMalloc (obmalloc.c:572)
==11235==    by 0x528599: PyThread_allocate_lock (thread_pthread.h:379)
==11235==    by 0x4C69B3: _PyEval_InitThreads (ceval.c:231)
==11235==    by 0x50F1EE: pycore_create_interpreter (pylifecycle.c:560)
==11235==    by 0x50FB8A: pyinit_config (pylifecycle.c:756)
==11235==    by 0x5102F7: pyinit_core (pylifecycle.c:923)
==11235==    by 0x510D7A: Py_InitializeFromConfig (pylifecycle.c:1133)
==11235==    by 0x41DAF1: pymain_init (main.c:66)
==11235==    by 0x41EB04: pymain_main (main.c:653)
==11235==    by 0x41EBAD: Py_BytesMain (main.c:686)
==11235==
msg365989 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-04-08 15:29
I confirm that I'm able to reproduce the issue on the master branch:

$ PYTHONMALLOC=malloc valgrind --leak-check=full --log-file=valgrind.log --num-callers=20 ./python -c pass

==44052== 32 bytes in 1 blocks are definitely lost in loss record 187 of 2,264
==44052==    at 0x483980B: malloc (vg_replace_malloc.c:309)
==44052==    by 0x46DA1E: _PyMem_RawMalloc (obmalloc.c:99)
==44052==    by 0x46EBE1: PyMem_RawMalloc (obmalloc.c:572)
==44052==    by 0x5475C7: PyThread_allocate_lock (thread_pthread.h:379)
==44052==    by 0x4ED6EF: _PyEval_InitThreads (ceval.c:296)
==44052==    by 0x52FE87: pycore_create_interpreter (pylifecycle.c:561)
==44052==    by 0x5316B3: pyinit_config (pylifecycle.c:757)
==44052==    by 0x532D38: pyinit_core (pylifecycle.c:924)
==44052==    by 0x5338F5: Py_InitializeFromConfig (pylifecycle.c:1134)
==44052==    by 0x41DA88: pymain_init (main.c:66)
==44052==    by 0x41EAAC: pymain_main (main.c:653)
==44052==    by 0x41EB39: Py_BytesMain (main.c:686)
==44052==    by 0x41D6CE: main (python.c:16)

> 50e6e991781db761c496561a995541ca8d83ff87 causes or exposes a
leak. Possibly the leak was there before but showed up under
"still reachable".

Python freed pending calls at exit. It's just that Valgrind decided to complain about them :-)

=> Attached PR fix the issue.

Note: the GIL is still leaked at exit. See "Don't destroy the GIL at exit" section of https://vstinner.github.io/daemon-threads-python-finalization-python32.html for the rationale.
msg365991 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-04-08 15:55
New changeset dda5d6e071c6a9d65993d45b90232565cfad2cde by Victor Stinner in branch 'master':
bpo-40226: PyInterpreterState_Delete() deletes pending calls (GH-19436)
https://github.com/python/cpython/commit/dda5d6e071c6a9d65993d45b90232565cfad2cde
msg365992 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-04-08 15:55
Fixed, thanks for the bug report Stefan ;-)
History
Date User Action Args
2020-04-08 15:55:23vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg365992

stage: patch review -> resolved
2020-04-08 15:55:06vstinnersetmessages: + msg365991
2020-04-08 15:29:02vstinnersetmessages: + msg365989
2020-04-08 15:27:17vstinnersetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request18790
2020-04-08 12:19:31skrahcreate