New submission from Charalampos Stratakis <cstra...@redhat.com>:

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|   }
1313|   

This was fixed on python3 with 
https://github.com/python/cpython/commit/19b52545df898ec911c44e29f75badb902924c0b

Partially backporting this change for this file should fix the issue.

----------
components: Extension Modules
messages: 336859
nosy: cstratak, vstinner
priority: normal
severity: normal
status: open
title: [2.7] Coverity scan: Modules/_ctypes/cfield.c , Variable "result" going 
out of scope
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36147>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to