[New-bugs-announce] [issue36292] Coverity scan: Resource leaks in longobject.c

Charalampos Stratakis report at bugs.python.org
Thu Mar 14 11:16:32 EDT 2019


New submission from Charalampos Stratakis <cstratak at redhat.com>:

The coverity scan was run on python2, however the same defect seems to exist in python3 as well.

Error: RESOURCE_LEAK (CWE-772): [#def69]
Python-2.7.15/Objects/longobject.c:3793: alloc_fn: Storage is returned from allocation function "_PyLong_New".
Python-2.7.15/Objects/longobject.c:76: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/longobject.c:76:5: identity_transfer: Passing "(PyVarObject *)PyObject_Malloc((size_t)(PyLong_Type.tp_basicsize + size * PyLong_Type.tp_itemsize + 7L & 0xfffffffffffffff8L))" as argument 1 to function "PyObject_InitVar", which returns that argument.
Python-2.7.15/Objects/object.c:237:5: return_parm: Returning parameter "op".
Python-2.7.15/Objects/longobject.c:76:5: return_alloc_fn: Directly returning storage allocated by "PyObject_InitVar".
Python-2.7.15/Objects/longobject.c:3793: var_assign: Assigning: "z" = storage returned from "_PyLong_New(size_a)".
Python-2.7.15/Objects/longobject.c:3797: var_assign: Assigning: "a" = "z".
Python-2.7.15/Objects/longobject.c:3847: leaked_storage: Variable "z" going out of scope leaks the storage it points to.
Python-2.7.15/Objects/longobject.c:3847: leaked_storage: Returning without freeing "a" leaks the storage that it points to.
 3845|       default:
 3846|           PyErr_BadArgument();
 3847|->         return NULL;
 3848|       }
 3849|   

Error: RESOURCE_LEAK (CWE-772): [#def70]
Python-2.7.15/Objects/longobject.c:3793: alloc_fn: Storage is returned from allocation function "_PyLong_New".
Python-2.7.15/Objects/longobject.c:76: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/longobject.c:76:5: identity_transfer: Passing "(PyVarObject *)PyObject_Malloc((size_t)(PyLong_Type.tp_basicsize + size * PyLong_Type.tp_itemsize + 7L & 0xfffffffffffffff8L))" as argument 1 to function "PyObject_InitVar", which returns that argument.
Python-2.7.15/Objects/object.c:237:5: return_parm: Returning parameter "op".
Python-2.7.15/Objects/longobject.c:76:5: return_alloc_fn: Directly returning storage allocated by "PyObject_InitVar".
Python-2.7.15/Objects/longobject.c:3793: var_assign: Assigning: "z" = storage returned from "_PyLong_New(size_a)".
Python-2.7.15/Objects/longobject.c:3797: var_assign: Assigning: "a" = "z".
Python-2.7.15/Objects/longobject.c:3820: var_assign: Assigning: "z" = "a".
Python-2.7.15/Objects/longobject.c:3820: var_assign: Assigning: "b" = "z".
Python-2.7.15/Objects/longobject.c:3847: leaked_storage: Variable "z" going out of scope leaks the storage it points to.
Python-2.7.15/Objects/longobject.c:3847: leaked_storage: Returning without freeing "b" leaks the storage that it points to.
 3845|       default:
 3846|           PyErr_BadArgument();
 3847|->         return NULL;
 3848|       }
 3849|

----------
components: Interpreter Core
messages: 337933
nosy: cstratak
priority: normal
severity: normal
status: open
title: Coverity scan: Resource leaks in longobject.c
versions: Python 2.7, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36292>
_______________________________________


More information about the New-bugs-announce mailing list