classification
Title: [2.7] Coverity scan: Modules/_hotshot.c , Variable "s1" going out of scope leaks the storage it points to.
Type: resource usage Stage: resolved
Components: Extension Modules Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cstratak, vstinner
Priority: normal Keywords: patch

Created on 2019-03-06 13:57 by cstratak, last changed 2019-03-14 15:11 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 12327 merged cstratak, 2019-03-14 13:42
Messages (4)
msg337301 - (view) Author: Charalampos Stratakis (cstratak) * Date: 2019-03-06 13:57
Coverity scan reports a leak on _hotshot.c: 

Python-2.7.15/Modules/_hotshot.c:442: alloc_arg: "unpack_string" allocates memory that is stored into "s1".
Python-2.7.15/Modules/_hotshot.c:329:5: alloc_fn: Storage is returned from allocation function "PyString_FromStringAndSize".
Python-2.7.15/Objects/stringobject.c:88:5: alloc_fn: Storage is returned from allocation function "PyObject_Malloc".
Python-2.7.15/Objects/obmalloc.c:982:5: alloc_fn: Storage is returned from allocation function "malloc".
Python-2.7.15/Objects/obmalloc.c:982:5: return_alloc_fn: Directly returning storage allocated by "malloc".
Python-2.7.15/Objects/stringobject.c:88:5: var_assign: Assigning: "op" = "PyObject_Malloc(37UL + size)".
Python-2.7.15/Objects/stringobject.c:111:5: return_alloc: Returning allocated memory "op".
Python-2.7.15/Modules/_hotshot.c:329:5: var_assign: Assigning: "*pvalue" = "PyString_FromStringAndSize(buf, len)".
Python-2.7.15/Modules/_hotshot.c:486: leaked_storage: Variable "s1" going out of scope leaks the storage it points to.
 484|           result = PyTuple_New(4);
 485|           if (result == NULL)
 486|->             return NULL;
 487|           PyTuple_SET_ITEM(result, 0, PyInt_FromLong(what));
 488|           PyTuple_SET_ITEM(result, 2, PyInt_FromLong(fileno));
msg337930 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-03-14 15:07
Note for myself: Python 3 isn't affected, _hotshot module has been removed from Python 3.
msg337931 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-03-14 15:11
New changeset 2832ad53358e3fbc4bdc601b9f3fa04dd0deae46 by Victor Stinner (stratakis) in branch '2.7':
[2.7] bpo-36212: Fix two possible reference leaks in the hotshot module (GH-12327)
https://github.com/python/cpython/commit/2832ad53358e3fbc4bdc601b9f3fa04dd0deae46
msg337932 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-03-14 15:11
Thanks Charalampos, I merged your PR. I made minor changes in your commit message.
History
Date User Action Args
2019-03-14 15:11:36vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg337932

stage: patch review -> resolved
2019-03-14 15:11:07vstinnersetmessages: + msg337931
2019-03-14 15:07:36vstinnersetnosy: + vstinner
messages: + msg337930
2019-03-14 13:42:52cstrataksetkeywords: + patch
stage: patch review
pull_requests: + pull_request12298
2019-03-06 13:57:29cstratakcreate