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: tokenizer.c memory leak in case of realloc failure
Type: Stage: resolved
Components: Versions: Python 3.8, Python 3.7, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cstratak, pablogsal, vstinner
Priority: normal Keywords: patch

Created on 2019-03-19 16:12 by cstratak, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 12442 merged pablogsal, 2019-03-19 16:18
PR 12470 merged vstinner, 2019-03-20 11:22
PR 12471 merged vstinner, 2019-03-20 11:25
Messages (4)
msg338375 - (view) Author: Charalampos Stratakis (cstratak) * Date: 2019-03-19 16:12
In tokenizer.c we have those lines of code [0]:

if (final_length < needed_length && final_length)
    /* should never fail */
    buf = PyMem_REALLOC(buf, final_length);
return buf;

If however that realloc fails, the memory allocated initially for buf, will not be freed.

[0] https://github.com/python/cpython/blob/master/Parser/tokenizer.c#L652
msg338391 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-03-19 17:18
New changeset cb90c89de14aab636739b3e810cf949e47b54a0c by Pablo Galindo in branch 'master':
bpo-36367: Free buffer if realloc fails in tokenize.c (GH-12442)
https://github.com/python/cpython/commit/cb90c89de14aab636739b3e810cf949e47b54a0c
msg338459 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-03-20 12:03
New changeset 65b9849f0f07a000d751c96d9d711aeb24c95224 by Victor Stinner in branch '3.7':
bpo-36367: Free buffer if realloc fails in tokenize.c (GH-12442) (GH-12471)
https://github.com/python/cpython/commit/65b9849f0f07a000d751c96d9d711aeb24c95224
msg338460 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-03-20 12:03
New changeset 469b0a50d990bcb441910b23194c131e403c2833 by Victor Stinner in branch '2.7':
bpo-36367: Free buffer if realloc fails in tokenize.c (GH-12442) (GH-12470)
https://github.com/python/cpython/commit/469b0a50d990bcb441910b23194c131e403c2833
History
Date User Action Args
2022-04-11 14:59:12adminsetgithub: 80548
2019-03-20 12:03:56vstinnersetversions: + Python 2.7, Python 3.7, Python 3.8
2019-03-20 12:03:43vstinnersetmessages: + msg338460
2019-03-20 12:03:18vstinnersetnosy: + vstinner
messages: + msg338459
2019-03-20 11:25:00vstinnersetpull_requests: + pull_request12423
2019-03-20 11:22:14vstinnersetpull_requests: + pull_request12422
2019-03-19 17:18:20pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-03-19 17:18:05pablogsalsetnosy: + pablogsal
messages: + msg338391
2019-03-19 16:18:55pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request12397
2019-03-19 16:12:41cstratakcreate