Issue 36147: [2.7] Coverity scan: Modules/_ctypes/cfield.c , Variable "result" going out of scope (original) (raw)

Issue36147

Created on 2019-02-28 18:03 by cstratak, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 12102 merged cstratak,2019-02-28 18:11
Messages (4)
msg336859 - (view) Author: Charalampos Stratakis (cstratak) * Date: 2019-02-28 18:03
Coverity scan on python2 resulted in this error. Python-2.7.15/Modules/_ctypes/cfield.c:1297: alloc_fn: Storage is returned from allocation function "PyString_FromString". Python-2.7.15/Objects/stringobject.c:143: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:143:5: var_assign: Assigning: "op" = "PyObject_Malloc(37UL + size)". Python-2.7.15/Objects/stringobject.c:164:5: return_alloc: Returning allocated memory "op". Python-2.7.15/Modules/_ctypes/cfield.c:1297: var_assign: Assigning: "result" = storage returned from "PyString_FromString((char *)ptr)". Python-2.7.15/Modules/_ctypes/cfield.c:1311: leaked_storage: Variable "result" going out of scope leaks the storage it points to. 1309| } else 1310 /* cannot shorten the result */ 1311 -> return PyString_FromStringAndSize(ptr, size); 1312
msg336861 - (view) Author: Charalampos Stratakis (cstratak) * Date: 2019-02-28 18:10
Also the change from PyUnicode_FromStringAndSize to PyBytes_FromStringAndSize happened here: https://bugs.python.org/issue8966
msg337303 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-03-06 14:14
New changeset 098b139816f379271b8d4de2561b5805dd47d229 by Victor Stinner (stratakis) in branch '2.7': bpo-36147: Fix a memory leak in ctypes s_get() (GH-12102) https://github.com/python/cpython/commit/098b139816f379271b8d4de2561b5805dd47d229
msg337305 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-03-06 14:34
Thanks Charalampos Stratakis!
History
Date User Action Args
2022-04-11 14:59:11 admin set github: 80328
2019-03-06 14:34:22 vstinner set status: open -> closedresolution: fixedstage: patch review -> resolved
2019-03-06 14:34:14 vstinner set messages: +
2019-03-06 14:14:10 vstinner set messages: +
2019-02-28 18:11:01 cstratak set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest12108>
2019-02-28 18:10:18 cstratak set messages: +
2019-02-28 18:03:20 cstratak create