Bug Summary

File:_helpermod.c
Warning:line 287, 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 _helpermod.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/_helpermod.c

numba/_helpermod.c

1/*
2Expose all functions as pointers in a dedicated C extension.
3*/
4#include "cext/cext.h"
5/* Import _pymodule.h first, for a recent _POSIX_C_SOURCE */
6#include "_pymodule.h"
7
8#include <math.h>
9#ifdef _MSC_VER
10 #define false0 0
11 #define true1 1
12 #define bool_Bool int
13#else
14 #include <stdbool.h>
15#endif
16
17/*
18Include C-extension here
19*/
20#include "cext/cext.h"
21
22/* Numba C helpers */
23#include "_helperlib.c"
24
25/* Numpy C math function exports */
26#include "_npymath_exports.c"
27
28static PyObject *
29build_c_helpers_dict(void)
30{
31 PyObject *dct = PyDict_New();
32 if (dct == NULL((void*)0))
33 goto error;
34
35#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 { \
36 PyObject *o = PyLong_FromVoidPtr(value); \
37 if (o == NULL((void*)0)) goto error; \
38 if (PyDict_SetItemString(dct, name, o)) { \
39 Py_DECREF(o)_Py_DECREF(((PyObject*)(o))); \
40 goto error; \
41 } \
42 Py_DECREF(o)_Py_DECREF(((PyObject*)(o))); \
43} while (0)
44
45#define declmethod(func) _declpointer(#func, &numba_##func)do { PyObject *o = PyLong_FromVoidPtr(&numba_##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)
46
47#define declpointer(ptr)do { PyObject *o = PyLong_FromVoidPtr(&numba_ptr); if (o ==
((void*)0)) goto error; if (PyDict_SetItemString(dct, "ptr",
o)) { _Py_DECREF(((PyObject*)(o))); goto error; } _Py_DECREF
(((PyObject*)(o))); } while (0)
_declpointer(#ptr, &numba_##ptr)do { PyObject *o = PyLong_FromVoidPtr(&numba_##ptr); if (
o == ((void*)0)) goto error; if (PyDict_SetItemString(dct, #ptr
, o)) { _Py_DECREF(((PyObject*)(o))); goto error; } _Py_DECREF
(((PyObject*)(o))); } while (0)
48
49 declmethod(fixed_fmod);
50 declmethod(fixed_fmodf);
51 declmethod(set_fnclex);
52
53 declmethod(sdiv);
54 declmethod(srem);
55 declmethod(udiv);
56 declmethod(urem);
57 declmethod(frexp);
58 declmethod(frexpf);
59 declmethod(ldexp);
60 declmethod(ldexpf);
61 declmethod(cpow);
62 declmethod(cpowf);
63 declmethod(erf);
64 declmethod(erff);
65 declmethod(erfc);
66 declmethod(erfcf);
67 declmethod(gamma);
68 declmethod(gammaf);
69 declmethod(lgamma);
70 declmethod(lgammaf);
71 declmethod(signbit);
72 declmethod(signbitf);
73 declmethod(complex_adaptor);
74 declmethod(adapt_ndarray);
75 declmethod(ndarray_new);
76 declmethod(extract_record_data);
77 declmethod(get_buffer);
78 declmethod(adapt_buffer);
79 declmethod(release_buffer);
80 declmethod(extract_np_datetime);
81 declmethod(create_np_datetime);
82 declmethod(extract_np_timedelta);
83 declmethod(create_np_timedelta);
84 declmethod(recreate_record);
85 declmethod(fptoui);
86 declmethod(fptouif);
87 declmethod(gil_ensure);
88 declmethod(gil_release);
89 declmethod(fatal_error);
90 declmethod(py_type);
91 declmethod(unpack_slice);
92 declmethod(do_raise);
93 declmethod(unpickle);
94 declmethod(attempt_nocopy_reshape);
95 declmethod(get_pyobject_private_data);
96 declmethod(set_pyobject_private_data);
97 declmethod(reset_pyobject_private_data);
98
99 /* BLAS / LAPACK */
100 declmethod(xxgemm);
101 declmethod(xxgemv);
102 declmethod(xxdot);
103 declmethod(xxgetrf);
104 declmethod(ez_xxgetri);
105 declmethod(xxpotrf);
106 declmethod(ez_rgeev);
107 declmethod(ez_cgeev);
108 declmethod(ez_xxxevd);
109 declmethod(ez_gesdd);
110 declmethod(ez_geqrf);
111 declmethod(ez_xxgqr);
112 declmethod(ez_gelsd);
113 declmethod(xgesv);
114 declmethod(xxnrm2);
115
116 /* PRNG support */
117 declmethod(get_py_random_state);
118 declmethod(get_np_random_state);
119 declmethod(rnd_shuffle);
120 declmethod(rnd_init);
121 declmethod(poisson_ptrs);
122
123 /* Unicode string support */
124 declmethod(extract_unicode);
125 declmethod(gettyperecord);
126 declmethod(get_PyUnicode_ExtendedCase);
127
128 /* for gdb breakpoint */
129 declmethod(gdb_breakpoint);
130
131 /* for dictionary support */
132 declmethod(test_dict);
133 declmethod(dict_new_minsize);
134 declmethod(dict_set_method_table);
135 declmethod(dict_free);
136 declmethod(dict_length);
137 declmethod(dict_lookup);
138 declmethod(dict_insert);
139 declmethod(dict_insert_ez);
140 declmethod(dict_delitem);
141 declmethod(dict_popitem);
142 declmethod(dict_iter_sizeof);
143 declmethod(dict_iter);
144 declmethod(dict_iter_next);
145 declmethod(dict_dump);
146
147 /* for list support */
148 declmethod(test_list);
149 declmethod(list_new);
150 declmethod(list_set_method_table);
151 declmethod(list_free);
152 declmethod(list_base_ptr);
153 declmethod(list_size_address);
154 declmethod(list_length);
155 declmethod(list_allocated);
156 declmethod(list_is_mutable);
157 declmethod(list_set_is_mutable);
158 declmethod(list_setitem);
159 declmethod(list_getitem);
160 declmethod(list_append);
161 declmethod(list_delitem);
162 declmethod(list_delete_slice);
163 declmethod(list_iter_sizeof);
164 declmethod(list_iter);
165 declmethod(list_iter_next);
166
167#define MATH_UNARY(F, R, A) declmethod(F);
168#define MATH_BINARY(F, R, A, B) declmethod(F);
169 #include "mathnames.h"
170#undef MATH_UNARY
171#undef MATH_BINARY
172
173#undef declmethod
174 return dct;
175error:
176 Py_XDECREF(dct)_Py_XDECREF(((PyObject*)(dct)));
177 return NULL((void*)0);
178}
179
180static int
181register_npymath_exports(PyObject *dct)
182{
183 size_t count = sizeof(npymath_exports) / sizeof(npymath_exports[0]);
184 size_t i;
185
186 for (i = 0; i < count; ++i) {
187 PyObject *ptr = PyLong_FromVoidPtr(npymath_exports[i].func);
188 if (ptr == NULL((void*)0))
189 return -1;
190 if (PyDict_SetItemString(dct, npymath_exports[i].name, ptr) < 0) {
191 Py_DECREF(ptr)_Py_DECREF(((PyObject*)(ptr)));
192 return -1;
193 }
194 Py_DECREF(ptr)_Py_DECREF(((PyObject*)(ptr)));
195 }
196
197 return 0;
198}
199
200static PyObject *
201build_npymath_exports_dict(void)
202{
203 PyObject *dct = PyDict_New();
204 if (dct != NULL((void*)0)) {
205 if (register_npymath_exports(dct) < 0)
206 Py_CLEAR(dct)do { PyObject *_py_tmp = ((PyObject*)(dct)); if (_py_tmp != (
(void*)0)) { (dct) = ((void*)0); _Py_DECREF(((PyObject*)(_py_tmp
))); } } while (0)
;
207 }
208 return dct;
209}
210
211
212/*
213 * Helper to deal with flushing stdout
214 */
215PyAPI_FUNC(void)void _numba_flush_stdout(void) ;
216
217void
218_numba_flush_stdout(void) {
219 fflush(stdoutstdout);
220}
221
222
223static PyMethodDef ext_methods[] = {
224 { "rnd_get_state", (PyCFunction) _numba_rnd_get_state, METH_O0x0008, NULL((void*)0) },
225 { "rnd_get_py_state_ptr", (PyCFunction) _numba_rnd_get_py_state_ptr, METH_NOARGS0x0004, NULL((void*)0) },
226 { "rnd_get_np_state_ptr", (PyCFunction) _numba_rnd_get_np_state_ptr, METH_NOARGS0x0004, NULL((void*)0) },
227 { "rnd_seed", (PyCFunction) _numba_rnd_seed, METH_VARARGS0x0001, NULL((void*)0) },
228 { "rnd_set_state", (PyCFunction) _numba_rnd_set_state, METH_VARARGS0x0001, NULL((void*)0) },
229 { "rnd_shuffle", (PyCFunction) _numba_rnd_shuffle, METH_O0x0008, NULL((void*)0) },
230 { "_import_cython_function", (PyCFunction) _numba_import_cython_function, METH_VARARGS0x0001, NULL((void*)0) },
231 { NULL((void*)0) },
232};
233
234/*
235 * These functions are exported by the module's DLL, to exercise ctypes / cffi
236 * without relying on libc availability (see https://bugs.python.org/issue23606)
237 */
238
239PyAPI_FUNC(double)double _numba_test_sin(double x);
240PyAPI_FUNC(double)double _numba_test_cos(double x);
241PyAPI_FUNC(double)double _numba_test_exp(double x);
242PyAPI_FUNC(void)void _numba_test_vsquare(int n, double *x, double *out);
243PyAPI_FUNC(double)double _numba_test_funcptr(double (*func)(double));
244PyAPI_FUNC(bool)_Bool _numba_test_boolean(void);
245
246double _numba_test_sin(double x)
247{
248 return sin(x);
249}
250
251double _numba_test_cos(double x)
252{
253 return cos(x);
254}
255
256double _numba_test_exp(double x)
257{
258 return exp(x);
259}
260
261void _numba_test_vsquare(int n, double *x, double *out)
262{
263 int i;
264 for (i = 0; i < n; i++)
265 out[i] = pow(x[i], 2.0);
266}
267
268void _numba_test_vcube(int n, double *x, double *out)
269{
270 int i;
271 for (i = 0; i < n; i++)
272 out[i] = pow(x[i], 3.0);
273}
274
275double _numba_test_funcptr(double (*func)(double))
276{
277 return func(1.5);
278}
279
280bool_Bool _numba_test_boolean()
281{
282 return true1;
283}
284
285MOD_INIT(_helperlib)PyObject* PyInit__helperlib(void) {
286 PyObject *m;
287 MOD_DEF(m, "_helperlib", "No docs", ext_methods){ static struct PyModuleDef moduledef = { { { 1, ((void*)0) }
, ((void*)0), 0, ((void*)0), }, "_helperlib", "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
288 if (m == NULL((void*)0))
4
Assuming 'm' is not equal to NULL
5
Taking false branch
289 return MOD_ERROR_VAL((void*)0);
290
291 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
292
293 PyModule_AddObject(m, "c_helpers", build_c_helpers_dict());
294 PyModule_AddObject(m, "npymath_exports", build_npymath_exports_dict());
295 PyModule_AddIntConstant(m, "long_min", LONG_MIN(-9223372036854775807L -1L));
296 PyModule_AddIntConstant(m, "long_max", LONG_MAX9223372036854775807L);
297 PyModule_AddIntConstant(m, "py_buffer_size", sizeof(Py_buffer));
298 PyModule_AddIntConstant(m, "py_gil_state_size", sizeof(PyGILState_STATE));
299 PyModule_AddIntConstant(m, "py_unicode_1byte_kind", PyUnicode_1BYTE_KIND);
300 PyModule_AddIntConstant(m, "py_unicode_2byte_kind", PyUnicode_2BYTE_KIND);
301 PyModule_AddIntConstant(m, "py_unicode_4byte_kind", PyUnicode_4BYTE_KIND);
302 PyModule_AddIntConstant(m, "py_unicode_wchar_kind", PyUnicode_WCHAR_KIND);
303 numba_rnd_ensure_global_init();
304
305 return MOD_SUCCESS_VAL(m)m;
306}

/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