classification
Title: Py_FrozenMain() resource leak and missing malloc checks
Type: behavior Stage: commit review
Components: Interpreter Core Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vstinner Nosy List: BreamoreBoy, christian.heimes, jcea, python-dev, thomaslee, vstinner
Priority: normal Keywords: patch

Created on 2012-09-09 22:09 by christian.heimes, last changed 2014-03-23 10:00 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
issue-15893-01.patch thomaslee, 2012-09-16 04:42 review
Messages (9)
msg170139 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2012-09-09 22:09
In Python/frozenmain.c the function Py_FrozenMain() doesn't handle argv_copy and argv_copy2 correctly. Both variables contain memory that is allocated with PyMem_Malloc(). argv_copy2 is never checked for NULL and both variables are not correctly cleaned up in error cases.

CID 486834: Resource leak (RESOURCE_LEAK)At (11): Variable "argv_copy" going out of scope leaks the storage it points to. 
CID 486835: Resource leak (RESOURCE_LEAK)At (9): Variable "argv_copy2" going out of scope leaks the storage it points to.

Suggested fix:
Separate var declaration from PyMem_Malloc() calls and use a goto label to clean up the variables and its content at the end of the function.
msg170547 - (view) Author: Thomas Lee (thomaslee) (Python committer) Date: 2012-09-16 04:42
Patch against hg tip attached.
msg193763 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-26 23:06
New changeset ab8121466785 by Victor Stinner in branch '3.3':
Issue #15893: frozenmain.c now handles PyMem_Malloc() failure
http://hg.python.org/cpython/rev/ab8121466785

New changeset 386ab2c12301 by Victor Stinner in branch 'default':
(Merge 3.3) Issue #15893: frozenmain.c now handles PyMem_Malloc() failure
http://hg.python.org/cpython/rev/386ab2c12301
msg193767 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-27 00:39
New changeset 47c6aa17fd90 by Victor Stinner in branch 'default':
Issue #15893: Improve error handling in main() and Py_FrozenMain()
http://hg.python.org/cpython/rev/47c6aa17fd90
msg193768 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-27 00:42
New changeset 12af9db5212a by Victor Stinner in branch '3.3':
Issue #15893: Remove dead code
http://hg.python.org/cpython/rev/12af9db5212a
msg193769 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-07-27 00:43
I didn't know Py_FrozenMain(). I upgraded it to use the same code than main().


Should I backport my fixes to Python 3.3 (except maybe 0001c4100823 which is risky).
msg200725 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-10-21 08:56
Victor, is here anything left to do?
msg214535 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-03-23 01:51
This believe that this can be closed as Python 3.3 is no longer taking fixes.
msg214558 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-03-23 10:00
> Victor, is here anything left to do?

The bug is correctly fixed in default. I don't really care of fixing such warning of static analyzer in older Python versions. It's more a theorical bug, it's a small memory leak and only occur if another error occurs. I just close the issue.
History
Date User Action Args
2014-03-23 10:00:53vstinnersetstatus: languishing -> closed
resolution: fixed
messages: + msg214558
2014-03-23 01:51:58BreamoreBoysetnosy: + BreamoreBoy
messages: + msg214535
2013-10-21 08:56:13christian.heimessetstatus: open -> languishing
assignee: vstinner
messages: + msg200725

stage: commit review
2013-07-27 00:43:49vstinnersetnosy: + vstinner
messages: + msg193769
2013-07-27 00:42:08python-devsetmessages: + msg193768
2013-07-27 00:39:51python-devsetmessages: + msg193767
2013-07-26 23:06:01python-devsetnosy: + python-dev
messages: + msg193763
2012-09-16 04:42:04thomasleesetfiles: + issue-15893-01.patch

nosy: + thomaslee
messages: + msg170547

keywords: + patch
2012-09-10 02:25:56jceasetnosy: + jcea
2012-09-09 22:09:57christian.heimescreate