Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-35720: Fixing a memory leak in Modules/main.c:pymain_parse_cmdline_impl #11528

Merged
merged 1 commit into from
Jan 22, 2019
Merged

bpo-35720: Fixing a memory leak in Modules/main.c:pymain_parse_cmdline_impl #11528

merged 1 commit into from
Jan 22, 2019

Conversation

Lucas-C
Copy link
Contributor

@Lucas-C Lucas-C commented Jan 11, 2019

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.

https://bugs.python.org/issue35720

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@Lucas-C
Copy link
Contributor Author

Lucas-C commented Jan 13, 2019

The Travis CI build failed with:

The job exceeded the maximum time limit for jobs, and has been terminated.

The Azure Pipeline build failed because of a column in the NEWS entry. I'm removing it:

Warning, treated as error:
[whatsnew/changelog:55] ":pymain" found in "Modules/main.c:pymain_parse_cmdline_impl"

Modules/main.c Outdated
@@ -435,7 +435,9 @@ pymain_clear_pymain(_PyMain *pymain)
{
#define CLEAR(ATTR) \
do { \
PyMem_RawFree(ATTR); \
if (ATTR != NULL) { \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if is useless: PyMem_RawFree(NULL) does nothing, the call is safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, removed

Modules/main.c Outdated
@@ -1381,7 +1383,8 @@ pymain_read_conf(_PyMain *pymain, _PyCoreConfig *config,
config->coerce_c_locale = new_coerce_c_locale;

/* The encoding changed: read again the configuration
with the new encoding */
with the new encoding, but free allocated memory beforehand: */
pymain_clear_pymain(pymain);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the call after pymain_clear_cmdline() call a few lines before, and leave the comment unchanged.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done

@@ -0,0 +1,2 @@
The experimental PEP 554 data channels now correctly pass negative PyLong
objects between subinterpreters on 32-bit systems. Patch by Michael Felt.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems to be unrelated!? cc @aixtools

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I included an extra commit by error. This is fixed now

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.
@miss-islington
Copy link
Contributor

Thanks @Lucas-C for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 22, 2019
…nGH-11528)

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.
(cherry picked from commit 35ca182)

Co-authored-by: Lucas Cimon <[email protected]>
@bedevere-bot
Copy link

GH-11648 is a backport of this pull request to the 3.7 branch.

miss-islington added a commit that referenced this pull request Jan 22, 2019
)

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.
(cherry picked from commit 35ca182)

Co-authored-by: Lucas Cimon <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants