Bug Summary

File:core/runtime/_nrt_pythonmod.c
Warning:line 193, column 5
PyObject ownership leak with reference count of 1

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name _nrt_pythonmod.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -analyzer-output=html -analyzer-checker=python -analyzer-disable-checker=deadcode -analyzer-config prune-paths=true,suppress-c++-stdlib=true,suppress-null-return-paths=false,crosscheck-with-z3=true,model-path=/opt/pyrefcon/lib/pyrefcon/models/models -analyzer-config experimental-enable-naive-ctu-analysis=true,ctu-dir=/tmp/pyrefcon/numba/csa-scan,ctu-index-name=/tmp/pyrefcon/numba/csa-scan/externalDefMap.txt,ctu-invocation-list=/tmp/pyrefcon/numba/csa-scan/invocations.yaml,display-ctu-progress=false -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=none -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb -fcoverage-compilation-dir=/tmp/pyrefcon/numba -resource-dir /opt/pyrefcon/lib/clang/13.0.0 -isystem /opt/pyrefcon/lib/pyrefcon/models/python3.8 -D NDEBUG -D _FORTIFY_SOURCE=2 -I /usr/lib/python3/dist-packages/numpy/core/include -internal-isystem /opt/pyrefcon/lib/clang/13.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-result -Wsign-compare -Wall -Wformat -Werror=format-security -Wformat -Werror=format-security -Wdate-time -fdebug-compilation-dir=/tmp/pyrefcon/numba -ferror-limit 19 -fwrapv -pthread -stack-protector 2 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/pyrefcon/numba/csa-scan/reports -x c numba/core/runtime/_nrt_pythonmod.c

numba/core/runtime/_nrt_pythonmod.c

1#define NUMBA_EXPORT_FUNC(_rettype)static _rettype static _rettype
2#define NUMBA_EXPORT_DATA(_vartype)static _vartype static _vartype
3
4#include "_nrt_python.c"
5
6static PyObject *
7memsys_shutdown(PyObject *self, PyObject *args) {
8 NRT_MemSys_shutdown();
9 Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (&
_Py_NoneStruct)
;
10}
11
12static PyObject *
13memsys_use_cpython_allocator(PyObject *self, PyObject *args) {
14 NRT_MemSys_set_allocator(PyMem_RawMalloc,
15 PyMem_RawRealloc,
16 PyMem_RawFree);
17 Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (&
_Py_NoneStruct)
;
18}
19
20static PyObject *
21memsys_set_atomic_inc_dec(PyObject *self, PyObject *args) {
22 PyObject *addr_inc_obj, *addr_dec_obj;
23 void *addr_inc, *addr_dec;
24 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "OO", &addr_inc_obj, &addr_dec_obj)) {
25 return NULL((void*)0);
26 }
27 addr_inc = PyLong_AsVoidPtr(addr_inc_obj);
28 if(PyErr_Occurred()) return NULL((void*)0);
29 addr_dec = PyLong_AsVoidPtr(addr_dec_obj);
30 if(PyErr_Occurred()) return NULL((void*)0);
31 NRT_MemSys_set_atomic_inc_dec(addr_inc, addr_dec);
32 Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (&
_Py_NoneStruct)
;
33}
34
35static PyObject *
36memsys_set_atomic_cas(PyObject *self, PyObject *args) {
37 PyObject *addr_cas_obj;
38 void *addr_cas;
39 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "O", &addr_cas_obj)) {
40 return NULL((void*)0);
41 }
42 addr_cas = PyLong_AsVoidPtr(addr_cas_obj);
43 if(PyErr_Occurred()) return NULL((void*)0);
44 NRT_MemSys_set_atomic_cas(addr_cas);
45 Py_RETURN_NONEreturn _Py_INCREF(((PyObject*)((&_Py_NoneStruct)))), (&
_Py_NoneStruct)
;
46}
47
48static PyObject *
49memsys_get_stats_alloc(PyObject *self, PyObject *args) {
50 return PyLong_FromSize_t(NRT_MemSys_get_stats_alloc());
51}
52
53static PyObject *
54memsys_get_stats_free(PyObject *self, PyObject *args) {
55 return PyLong_FromSize_t(NRT_MemSys_get_stats_free());
56}
57
58static PyObject *
59memsys_get_stats_mi_alloc(PyObject *self, PyObject *args) {
60 return PyLong_FromSize_t(NRT_MemSys_get_stats_mi_alloc());
61}
62
63static PyObject *
64memsys_get_stats_mi_free(PyObject *self, PyObject *args) {
65 return PyLong_FromSize_t(NRT_MemSys_get_stats_mi_free());
66}
67
68
69/*
70 * Create a new MemInfo with a owner PyObject
71 */
72static PyObject *
73meminfo_new(PyObject *self, PyObject *args) {
74 PyObject *addr_data_obj;
75 void *addr_data;
76 PyObject *ownerobj;
77 NRT_MemInfo *mi;
78 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "OO", &addr_data_obj, &ownerobj)) {
79 return NULL((void*)0);
80 }
81 addr_data = PyLong_AsVoidPtr(addr_data_obj);
82 if (PyErr_Occurred())
83 return NULL((void*)0);
84 mi = NRT_meminfo_new_from_pyobject(addr_data, ownerobj);
85 return PyLong_FromVoidPtr(mi);
86}
87
88/*
89 * Create a new MemInfo with a new NRT allocation
90 */
91static PyObject *
92meminfo_alloc(PyObject *self, PyObject *args) {
93 NRT_MemInfo *mi;
94 Py_ssize_t size;
95 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "n", &size)) {
96 return NULL((void*)0);
97 }
98 mi = NRT_MemInfo_alloc(size);
99 return PyLong_FromVoidPtr(mi);
100}
101
102/*
103 * Like meminfo_alloc but set memory to zero after allocation and before
104 * deallocation.
105 */
106static PyObject *
107meminfo_alloc_safe(PyObject *self, PyObject *args) {
108 NRT_MemInfo *mi;
109 Py_ssize_t size;
110 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "n", &size)) {
111 return NULL((void*)0);
112 }
113 mi = NRT_MemInfo_alloc_safe(size);
114 return PyLong_FromVoidPtr(mi);
115}
116
117static PyMethodDef ext_methods[] = {
118#define declmethod(func) { #func , ( PyCFunction )func , METH_VARARGS0x0001 , NULL((void*)0) }
119#define declmethod_noargs(func){ "func" , ( PyCFunction )func , 0x0004, ((void*)0) } { #func , ( PyCFunction )func , METH_NOARGS0x0004, NULL((void*)0) }
120 declmethod_noargs(memsys_use_cpython_allocator){ "memsys_use_cpython_allocator" , ( PyCFunction )memsys_use_cpython_allocator
, 0x0004, ((void*)0) }
,
121 declmethod_noargs(memsys_shutdown){ "memsys_shutdown" , ( PyCFunction )memsys_shutdown , 0x0004
, ((void*)0) }
,
122 declmethod(memsys_set_atomic_inc_dec),
123 declmethod(memsys_set_atomic_cas),
124 declmethod_noargs(memsys_get_stats_alloc){ "memsys_get_stats_alloc" , ( PyCFunction )memsys_get_stats_alloc
, 0x0004, ((void*)0) }
,
125 declmethod_noargs(memsys_get_stats_free){ "memsys_get_stats_free" , ( PyCFunction )memsys_get_stats_free
, 0x0004, ((void*)0) }
,
126 declmethod_noargs(memsys_get_stats_mi_alloc){ "memsys_get_stats_mi_alloc" , ( PyCFunction )memsys_get_stats_mi_alloc
, 0x0004, ((void*)0) }
,
127 declmethod_noargs(memsys_get_stats_mi_free){ "memsys_get_stats_mi_free" , ( PyCFunction )memsys_get_stats_mi_free
, 0x0004, ((void*)0) }
,
128 declmethod(meminfo_new),
129 declmethod(meminfo_alloc),
130 declmethod(meminfo_alloc_safe),
131 { NULL((void*)0) },
132#undef declmethod
133};
134
135
136
137static PyObject *
138build_c_helpers_dict(void)
139{
140 PyObject *dct = PyDict_New();
141 if (dct == NULL((void*)0))
142 goto error;
143
144#define _declpointer(name, value)do { PyObject *o = PyLong_FromVoidPtr(value); if (o == ((void
*)0)) goto error; if (PyDict_SetItemString(dct, name, o)) { _Py_DECREF
(((PyObject*)(o))); goto error; } _Py_DECREF(((PyObject*)(o))
); } while (0)
do { \
145 PyObject *o = PyLong_FromVoidPtr(value); \
146 if (o == NULL((void*)0)) goto error; \
147 if (PyDict_SetItemString(dct, name, o)) { \
148 Py_DECREF(o)_Py_DECREF(((PyObject*)(o))); \
149 goto error; \
150 } \
151 Py_DECREF(o)_Py_DECREF(((PyObject*)(o))); \
152} while (0)
153
154#define declmethod(func) _declpointer(#func, &NRT_##func)do { PyObject *o = PyLong_FromVoidPtr(&NRT_##func); if (o
== ((void*)0)) goto error; if (PyDict_SetItemString(dct, #func
, o)) { _Py_DECREF(((PyObject*)(o))); goto error; } _Py_DECREF
(((PyObject*)(o))); } while (0)
155#define declmethod_internal(func) _declpointer(#func, &func)do { PyObject *o = PyLong_FromVoidPtr(&func); if (o == ((
void*)0)) goto error; if (PyDict_SetItemString(dct, #func, o)
) { _Py_DECREF(((PyObject*)(o))); goto error; } _Py_DECREF(((
PyObject*)(o))); } while (0)
156
157declmethod(adapt_ndarray_from_python);
158declmethod(adapt_ndarray_to_python_acqref);
159declmethod(adapt_buffer_from_python);
160declmethod(meminfo_new_from_pyobject);
161declmethod(meminfo_as_pyobject);
162declmethod(meminfo_from_pyobject);
163declmethod(MemInfo_alloc);
164declmethod(MemInfo_alloc_safe);
165declmethod(MemInfo_alloc_aligned);
166declmethod(MemInfo_alloc_safe_aligned);
167declmethod(MemInfo_alloc_safe_aligned_external);
168declmethod_internal(_nrt_get_sample_external_allocator);
169declmethod(MemInfo_alloc_dtor_safe);
170declmethod(MemInfo_call_dtor);
171declmethod(MemInfo_new_varsize);
172declmethod(MemInfo_new_varsize_dtor);
173declmethod(MemInfo_varsize_alloc);
174declmethod(MemInfo_data);
175declmethod(MemInfo_varsize_free);
176declmethod(MemInfo_varsize_realloc);
177declmethod(MemInfo_release);
178declmethod(Allocate);
179declmethod(Free);
180declmethod(get_api);
181
182
183#undef declmethod
184#undef declmethod_internal
185 return dct;
186error:
187 Py_XDECREF(dct)_Py_XDECREF(((PyObject*)(dct)));
188 return NULL((void*)0);
189}
190
191MOD_INIT(_nrt_python)PyObject* PyInit__nrt_python(void) {
192 PyObject *m;
193 MOD_DEF(m, "_nrt_python", "No docs", ext_methods){ static struct PyModuleDef moduledef = { { { 1, ((void*)0) }
, ((void*)0), 0, ((void*)0), }, "_nrt_python", "No docs", -1,
ext_methods, ((void*)0), ((void*)0), ((void*)0), ((void*)0) }
; m = PyModule_Create2(&moduledef, 1013); }
1
Calling 'PyModule_Create2'
3
Returning from 'PyModule_Create2'
7
PyObject ownership leak with reference count of 1
194 if (m == NULL((void*)0))
4
Assuming 'm' is not equal to NULL
5
Taking false branch
195 return MOD_ERROR_VAL((void*)0);
196 import_array(){if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(
PyExc_ImportError, "numpy.core.multiarray failed to import");
return ((void*)0); } }
;
6
Taking true branch
197 NRT_MemSys_init();
198 if (init_nrt_python_module(m))
199 return MOD_ERROR_VAL((void*)0);
200
201 Py_INCREF(&MemInfoType)_Py_INCREF(((PyObject*)(&MemInfoType)));
202 PyModule_AddObject(m, "_MemInfo", (PyObject *) (&MemInfoType));
203
204 PyModule_AddObject(m, "c_helpers", build_c_helpers_dict());
205
206 return MOD_SUCCESS_VAL(m)m;
207}

/opt/pyrefcon/lib/pyrefcon/models/models/PyModule_Create2.model

1#ifndef PyModule_Create2
2PyObject* clang_analyzer_PyObject_New_Reference();
3PyObject* PyModule_Create2(PyModuleDef *def, int module_api_version) {
4 return clang_analyzer_PyObject_New_Reference();
2
Setting reference count to 1
5}
6#else
7#warning "API PyModule_Create2 is defined as a macro."
8#endif