classification
Title: Memory leak in Modules/main.c:pymain_parse_cmdline_impl when using the CLI flag
Type: resource usage Stage: resolved
Components: Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Lucas Cimon, miss-islington, vstinner
Priority: normal Keywords: patch, patch, patch

Created on 2019-01-11 19:14 by Lucas Cimon, last changed 2019-01-22 16:43 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11528 merged python-dev, 2019-01-11 19:16
PR 11528 merged python-dev, 2019-01-11 19:16
PR 11528 merged python-dev, 2019-01-11 19:16
PR 11648 merged miss-islington, 2019-01-22 16:16
PR 11648 merged miss-islington, 2019-01-22 16:16
Messages (4)
msg333499 - (view) Author: Lucas Cimon (Lucas Cimon) * Date: 2019-01-11 19:14
Hi.

I think I have found a minor memory leak in Modules/main.c:pymain_parse_cmdline_impl.

When the loop in the pymain_read_conf function in this same file
calls pymain_init_cmdline_argv a 2nd time, the pymain->command
buffer of wchar_t is overriden and the previously allocated memory
is never freed.

I haven't written any code test to reproduce this,
but it can be tested easily with gdb:
```
gdb -- bin/python3 -c pass
start
b Modules/main.c:587
b pymain_clear_pymain
c
c
```
You'll see that PyMem_RawMalloc is called twice without pymain->command ever being freed in pymain_clear_pymain.

I have a patch coming as PR on GitHub

I'd be glad to have your feedback on this issue and my proposal for a fix.

Regards.
msg334217 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-01-22 16:15
New changeset 35ca1820e19f81f69073f294503cdcd708fe490f by Victor Stinner (Lucas Cimon) in branch 'master':
bpo-35720: Fixing a memory leak in pymain_parse_cmdline_impl() (GH-11528)
https://github.com/python/cpython/commit/35ca1820e19f81f69073f294503cdcd708fe490f
msg334220 - (view) Author: miss-islington (miss-islington) Date: 2019-01-22 16:42
New changeset f71e7433ebccb2e3a2665b93bb84de38f9c581c8 by Miss Islington (bot) in branch '3.7':
bpo-35720: Fixing a memory leak in pymain_parse_cmdline_impl() (GH-11528)
https://github.com/python/cpython/commit/f71e7433ebccb2e3a2665b93bb84de38f9c581c8
msg334221 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-01-22 16:43
Thanks Lucas Cimon!
History
Date User Action Args
2019-01-22 16:43:52vstinnersetstatus: open -> closed
messages: + msg334221

keywords: patch, patch, patch
resolution: fixed
stage: patch review -> resolved
2019-01-22 16:42:16miss-islingtonsetnosy: + miss-islington
messages: + msg334220
2019-01-22 16:16:09miss-islingtonsetpull_requests: + pull_request11434
2019-01-22 16:16:03miss-islingtonsetpull_requests: + pull_request11433
2019-01-22 16:15:05vstinnersetmessages: + msg334217
2019-01-14 10:05:04SilentGhostsetkeywords: patch, patch, patch
nosy: + vstinner

type: resource usage
versions: + Python 3.7, Python 3.8
2019-01-11 19:16:22python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request11118
2019-01-11 19:16:20python-devsetkeywords: + patch
stage: (no value)
pull_requests: + pull_request11117
2019-01-11 19:16:17python-devsetkeywords: + patch
stage: (no value)
pull_requests: + pull_request11116
2019-01-11 19:14:02Lucas Cimoncreate