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-36262: Fix _Py_dg_strtod() memory leak (goto undfl) #12276

Merged
merged 2 commits into from
Mar 13, 2019
Merged

bpo-36262: Fix _Py_dg_strtod() memory leak (goto undfl) #12276

merged 2 commits into from
Mar 13, 2019

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Mar 11, 2019

Fix an unlikely memory leak on conversion from string to float in the
function _Py_dg_strtod() used by float(str), complex(str),
pickle.load(), marshal.load(), etc.

Fix an unlikely memory leak in _Py_dg_strtod() on "undfl:" label:
rewrite memory management in this function to always release all
memory before exiting the function. Initialize variables to NULL, and
set them to NULL after calling Bfree() at the "cont:" label.

Note: Bfree(NULL) is well defined: it does nothing.

https://bugs.python.org/issue36262

Fix an unlikely memory leak on conversion from string to float in the
function _Py_dg_strtod() used by float(str), complex(str),
pickle.load(), marshal.load(), etc.

Fix an unlikely memory leak in _Py_dg_strtod() on "undfl:" label:
rewrite memory management in this function to always release all
memory before exiting the function. Initialize variables to NULL, and
set them to NULL after calling Bfree() at the "cont:" label.

Note: Bfree(NULL) is well defined: it does nothing.
Copy link
Member

@mdickinson mdickinson left a comment

Choose a reason for hiding this comment

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

Changes LGTM. Is there any easy way to get a re-run of the coverity scan on this file to check that they agree that the leak is fixed?

@vstinner
Copy link
Member Author

Changes LGTM. Is there any easy way to get a re-run of the coverity scan on this file to check that they agree that the leak is fixed?

I created an internal PR at Red Hat where we have a Coverity covscan job running. For an unknown reason, this issue was only spotted on Python 2, not on Python 3, whereas Python 2 and 3 use the same code for Python/dtoa.c (both have https://bugs.python.org/issue36262 leak).

I will keep an eye on the internal PR to see if the covscan result changes.

@stratakis
Copy link
Contributor

I can verify that with those changes, our internal instance of coverity scan doesn't report any leaks anymore for dtoa.c

@vstinner vstinner merged commit 9776b06 into python:master Mar 13, 2019
@vstinner vstinner deleted the dtoa_goto_bfree branch March 13, 2019 16:55
@miss-islington
Copy link
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@vstinner
Copy link
Member Author

Thanks for the review @mdickinson and thanks @stratakis for checking Coverity! I pushed a second minor cleanup change to make memory management a little bit more explicit.

@miss-islington
Copy link
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 2.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

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

@bedevere-bot
Copy link

GH-12332 is a backport of this pull request to the 2.7 branch.

vstinner added a commit that referenced this pull request Mar 14, 2019
…H-12331)

Fix an unlikely memory leak on conversion from string to float in the
function _Py_dg_strtod() used by float(str), complex(str),
pickle.load(), marshal.load(), etc.

Fix an unlikely memory leak in _Py_dg_strtod() on "undfl:" label:
rewrite memory management in this function to always release all
memory before exiting the function. Initialize variables to NULL, and
set them to NULL after calling Bfree() at the "cont:" label.

Note: Bfree(NULL) is well defined: it does nothing.

(cherry picked from commit 9776b06)
vstinner added a commit that referenced this pull request Mar 14, 2019
…H-12332)

Fix an unlikely memory leak on conversion from string to float in the
function _Py_dg_strtod() used by float(str), complex(str),
pickle.load(), marshal.load(), etc.

Fix an unlikely memory leak in _Py_dg_strtod() on "undfl:" label:
rewrite memory management in this function to always release all
memory before exiting the function. Initialize variables to NULL, and
set them to NULL after calling Bfree() at the "cont:" label.

Note: Bfree(NULL) is well defined: it does nothing.

(cherry picked from commit 9776b06)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants