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: `growable_int_array type_ignores` in parsetok.c is not always freed.
Type: resource usage Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, pablogsal, umanwizard
Priority: normal Keywords: patch

Created on 2019-02-11 23:05 by umanwizard, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11832 merged pablogsal, 2019-02-12 23:11
Messages (4)
msg335274 - (view) Author: Brennan Vincent (umanwizard) Date: 2019-02-11 23:05
To reproduce:

(1) build python: `../configure --prefix=$HOME/prefix --with-pydebug --without-pymalloc && make install`

(2) run with valgrind: `valgrind --leak-check=full ~/prefix/bin/python3`

(3) exit immediately from the interpreter by pressing ^D

(4) Note the following output from Valgrind:

```
==3810071== 40 bytes in 1 blocks are definitely lost in loss record 3 of 527
==3810071==    at 0x4C28B5F: malloc (vg_replace_malloc.c:299)
==3810071==    by 0x59ED58: growable_int_array_init (parsetok.c:27)
==3810071==    by 0x59EE14: parsetok (parsetok.c:235)
==3810071==    by 0x59F697: PyParser_ParseFileObject (parsetok.c:176)
==3810071==    by 0x522E85: PyParser_ASTFromFileObject (pythonrun.c:1224)
==3810071==    by 0x5231E9: PyRun_InteractiveOneObjectEx (pythonrun.c:238)
==3810071==    by 0x5234D0: PyRun_InteractiveLoopFlags (pythonrun.c:120)
==3810071==    by 0x523BF2: PyRun_AnyFileExFlags (pythonrun.c:78)
==3810071==    by 0x4204FE: pymain_run_stdin (main.c:1185)
==3810071==    by 0x42126B: pymain_run_python (main.c:1675)
==3810071==    by 0x422EE0: pymain_main (main.c:1820)
==3810071==    by 0x422F75: _Py_UnixMain (main.c:1857)
```

Reproduced on git commit hash 522346d792d9013140a3f4ad3534ac10f38d9085 .
msg335287 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2019-02-12 05:36
Thanks for the report!

I think I see a path through the code that doesn't free the memory.

Does this patch fix it?

diff --git a/Parser/parsetok.c b/Parser/parsetok.c
index 1fa4a1286b..6a96f6bc5a 100644
--- a/Parser/parsetok.c
+++ b/Parser/parsetok.c
@@ -370,7 +370,6 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
                                 type_ignores.items[i], 0);
             }
         }
-        growable_int_array_deallocate(&type_ignores);
 
 #ifndef PGEN
         /* Check that the source for a single input statement really
@@ -405,6 +404,8 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
     else
         n = NULL;
 
+    growable_int_array_deallocate(&type_ignores);
+
 #ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
     *flags = ps->p_flags;
 #endif
msg335340 - (view) Author: Brennan Vincent (umanwizard) Date: 2019-02-12 18:10
Hi Guido,

I have tried applying your patch. It seems to fix the issue (Valgrind no longer reports memory definitely lost).
msg335384 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2019-02-13 02:43
Fixed by b9d2e97601847a1845bf96e2895a6214f02b92a6 (GH-11832).
History
Date User Action Args
2022-04-11 14:59:11adminsetgithub: 80154
2019-02-13 02:43:45gvanrossumsetstatus: open -> closed

nosy: + pablogsal
messages: + msg335384

resolution: fixed
stage: patch review -> resolved
2019-02-12 23:11:05pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request11863
2019-02-12 18:10:25umanwizardsetmessages: + msg335340
2019-02-12 05:36:43gvanrossumsetmessages: + msg335287
2019-02-12 05:03:50xtreaksetnosy: + gvanrossum
2019-02-11 23:05:56umanwizardcreate