Bug Summary

File:_dynfuncmod.c
Warning:line 36, column 21
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 _dynfuncmod.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 -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/_dynfuncmod.c

numba/_dynfuncmod.c

1#include "_dynfunc.c"
2
3/* Python-facing function to dynamically create a new C function object */
4static PyObject*
5make_function(PyObject *self, PyObject *args)
6{
7 PyObject *module, *fname, *fdoc, *fnaddrobj;
8 void *fnaddr;
9 EnvironmentObject *env;
10 PyObject *keepalive;
11
12 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "OOOOO!|O",
13 &module, &fname, &fdoc, &fnaddrobj, &EnvironmentType, &env,
14 &keepalive)) {
15 return NULL((void*)0);
16 }
17
18 fnaddr = PyLong_AsVoidPtr(fnaddrobj);
19 if (fnaddr == NULL((void*)0) && PyErr_Occurred())
20 return NULL((void*)0);
21
22 return pycfunction_new(module, fname, fdoc, fnaddr, env, keepalive);
23}
24
25static PyMethodDef ext_methods[] = {
26#define declmethod(func) { #func , ( PyCFunction )func , METH_VARARGS0x0001 , NULL((void*)0) }
27 declmethod(make_function),
28 { NULL((void*)0) },
29#undef declmethod
30};
31
32
33static PyObject *
34build_c_helpers_dict(void)
35{
36 PyObject *dct = PyDict_New();
7
Calling 'PyDict_New'
9
Returning from 'PyDict_New'
18
PyObject ownership leak with reference count of 1
37 if (dct == NULL((void*)0))
10
Assuming 'dct' is not equal to NULL
11
Taking false branch
38 goto error;
39
40#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 { \
41 PyObject *o = PyLong_FromVoidPtr(value); \
42 if (o == NULL((void*)0)) goto error; \
43 if (PyDict_SetItemString(dct, name, o)) { \
44 Py_DECREF(o)_Py_DECREF(((PyObject*)(o))); \
45 goto error; \
46 } \
47 Py_DECREF(o)_Py_DECREF(((PyObject*)(o))); \
48} while (0)
49
50#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)
51
52#define declpointer(ptr)do { PyObject *o = PyLong_FromVoidPtr(&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, &ptr)do { PyObject *o = PyLong_FromVoidPtr(&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)
53
54 declmethod(make_generator);
12
Assuming 'o' is not equal to null
13
Taking false branch
14
Assuming the condition is false
15
Taking false branch
16
Loop condition is false. Exiting loop
55
56#undef declmethod
57 return dct;
58error:
59 Py_XDECREF(dct)_Py_XDECREF(((PyObject*)(dct)));
60 return NULL((void*)0);
61}
62
63MOD_INIT(_dynfunc)PyObject* PyInit__dynfunc(void) {
64 PyObject *m, *impl_info;
65
66 MOD_DEF(m, "_dynfunc", "No docs", ext_methods){ static struct PyModuleDef moduledef = { { { 1, ((void*)0) }
, ((void*)0), 0, ((void*)0), }, "_dynfunc", "No docs", -1, ext_methods
, ((void*)0), ((void*)0), ((void*)0), ((void*)0) }; m = PyModule_Create2
(&moduledef, 1013); }
67 if (m == NULL((void*)0))
1
Assuming 'm' is not equal to NULL
2
Taking false branch
68 return MOD_ERROR_VAL((void*)0);
69
70 if (init_dynfunc_module(m))
3
Taking false branch
71 return MOD_ERROR_VAL((void*)0);
72
73 impl_info = Py_BuildValue_Py_BuildValue_SizeT(
74 "{snsnsn}",
75 "offsetof_closure_body", offsetof(ClosureObject, env)__builtin_offsetof(ClosureObject, env),
76 "offsetof_env_body", offsetof(EnvironmentObject, globals)__builtin_offsetof(EnvironmentObject, globals),
77 "offsetof_generator_state", offsetof(GeneratorObject, state)__builtin_offsetof(GeneratorObject, state)
78 );
79 if (impl_info == NULL((void*)0))
4
Assuming 'impl_info' is not equal to NULL
5
Taking false branch
80 return MOD_ERROR_VAL((void*)0);
81 PyModule_AddObject(m, "_impl_info", impl_info);
82
83 Py_INCREF(&ClosureType)_Py_INCREF(((PyObject*)(&ClosureType)));
84 PyModule_AddObject(m, "_Closure", (PyObject *) (&ClosureType));
85 Py_INCREF(&EnvironmentType)_Py_INCREF(((PyObject*)(&EnvironmentType)));
86 PyModule_AddObject(m, "Environment", (PyObject *) (&EnvironmentType));
87 Py_INCREF(&GeneratorType)_Py_INCREF(((PyObject*)(&GeneratorType)));
88 PyModule_AddObject(m, "_Generator", (PyObject *) (&GeneratorType));
89
90 PyModule_AddObject(m, "c_helpers", build_c_helpers_dict());
6
Calling 'build_c_helpers_dict'
17
Returning from 'build_c_helpers_dict'
91
92 return MOD_SUCCESS_VAL(m)m;
93}

/opt/pyrefcon/lib/pyrefcon/models/models/PyDict_New.model

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