Bug Summary

File:experimental/jitclass/_box.c
Warning:line 176, column 24
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 _box.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/experimental/jitclass/_box.c

numba/experimental/jitclass/_box.c

1/*
2Implements jitclass Box type in python c-api level.
3*/
4#include "../../_pymodule.h"
5
6typedef struct {
7 PyObject_HEADPyObject ob_base;
8 void *meminfoptr, *dataptr;
9} BoxObject;
10
11
12/* Store function defined in numba.core.runtime._nrt_python for use in box_dealloc.
13 * It points to a function is code segment that does not need user deallocation
14 * and does not disappear while the process is stil running.
15 */
16static void (*MemInfo_release)(void*) = NULL((void*)0);
17
18
19/*
20 * Box.__init__()
21 * Takes no arguments.
22 * meminfoptr and dataptr are set to NULL.
23 */
24static
25int Box_init(BoxObject *self, PyObject *args, PyObject *kwds) {
26 static char *keywords[] = {NULL((void*)0)};
27 if (!PyArg_ParseTupleAndKeywords_PyArg_ParseTupleAndKeywords_SizeT(args, kwds, "", keywords))
28 {
29 return -1;
30 }
31 /* Initialize attributes to NULL */
32 self->meminfoptr = NULL((void*)0);
33 self->dataptr = NULL((void*)0);
34 return 0;
35}
36
37/*
38 * Box destructor
39 * Release MemInfo pointed by meminfoptr.
40 * Free the instance.
41 */
42static
43void box_dealloc(BoxObject *box)
44{
45 if (box->meminfoptr) MemInfo_release((void*)box->meminfoptr);
46 Py_TYPE(box)(((PyObject*)(box))->ob_type)->tp_free((PyObject *) box);
47}
48
49
50static const char Box_doc[] = "A box for numba created jit-class instance";
51
52
53static PyTypeObject BoxType = {
54 PyVarObject_HEAD_INIT(NULL, 0){ { 1, ((void*)0) }, 0 },
55 "_box.Box", /*tp_name*/
56 sizeof(BoxObject), /*tp_basicsize*/
57 0, /*tp_itemsize*/
58 (destructor)box_dealloc, /*tp_dealloc*/
59 0, /*tp_print*/
60 0, /*tp_getattr*/
61 0, /*tp_setattr*/
62 0, /*tp_compare*/
63 0, /*tp_repr*/
64 0, /*tp_as_number*/
65 0, /*tp_as_sequence*/
66 0, /*tp_as_mapping*/
67 0, /*tp_hash */
68 0, /*tp_call*/
69 0, /*tp_str*/
70 0, /*tp_getattro*/
71 0, /*tp_setattro*/
72 0, /*tp_as_buffer*/
73 Py_TPFLAGS_DEFAULT( 0 | (1UL << 18) | 0) | Py_TPFLAGS_BASETYPE(1UL << 10), /*tp_flags*/
74 Box_doc, /* tp_doc */
75 0, /* tp_traverse */
76 0, /* tp_clear */
77 0, /* tp_richcompare */
78 0, /* tp_weaklistoffset */
79 0, /* tp_iter */
80 0, /* tp_iternext */
81 0, /* tp_methods */
82 0, /* tp_members */
83 0, /* tp_getset */
84 0, /* tp_base */
85 0, /* tp_dict */
86 0, /* tp_descr_get */
87 0, /* tp_descr_set */
88 0, /* tp_dictoffset */
89 (initproc)Box_init, /* tp_init */
90 0, /* tp_alloc */
91 PyType_GenericNew, /* tp_new */
92};
93
94
95/* Import MemInfo_Release from numba.core.runtime._nrt_python once for use in
96 * Box_dealloc.
97 */
98static void *
99import_meminfo_release(void) {
100 PyObject *nrtmod = NULL((void*)0);
101 PyObject *helperdct = NULL((void*)0);
102 PyObject *mi_rel_fn = NULL((void*)0);
103 void *fnptr = NULL((void*)0);
104 /* from numba.core.runtime import _nrt_python */
105 nrtmod = PyImport_ImportModule("numba.core.runtime._nrt_python");
106 if (!nrtmod) goto cleanup;
107 /* helperdct = _nrt_python.c_helpers */
108 helperdct = PyObject_GetAttrString(nrtmod, "c_helpers");
109 if (!helperdct) goto cleanup;
110 /* helperdct['MemInfo_release'] */
111 mi_rel_fn = PyDict_GetItemString(helperdct, "MemInfo_release");
112 if (!mi_rel_fn) goto cleanup;
113 fnptr = PyLong_AsVoidPtr(mi_rel_fn);
114
115cleanup:
116 Py_XDECREF(nrtmod)_Py_XDECREF(((PyObject*)(nrtmod)));
117 Py_XDECREF(helperdct)_Py_XDECREF(((PyObject*)(helperdct)));
118 return fnptr;
119}
120
121/* Debug utils.
122 * Get internal dataptr field from Box.
123 */
124static
125PyObject* box_get_dataptr(PyObject *self, PyObject *args) {
126 BoxObject *box;
127 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "O!", &BoxType, (PyObject*)&box))
128 return NULL((void*)0);
129 return PyLong_FromVoidPtr(box->dataptr);
130}
131
132/* Debug utils.
133 * Get internal meminfoptr field from Box.
134 */
135static
136PyObject* box_get_meminfoptr(PyObject *self, PyObject *args) {
137 BoxObject *box;
138 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "O!", &BoxType, (PyObject*)&box))
139 return NULL((void*)0);
140 return PyLong_FromVoidPtr(box->meminfoptr);
141}
142
143
144static PyMethodDef ext_methods[] = {
145#define declmethod(func) { #func , ( PyCFunction )func , METH_VARARGS0x0001 , NULL((void*)0) }
146 declmethod(box_get_dataptr),
147 declmethod(box_get_meminfoptr),
148 { NULL((void*)0) },
149#undef declmethod
150};
151
152
153MOD_INIT(_box)PyObject* PyInit__box(void) {
154 PyObject *m;
155
156 MOD_DEF(m, "_box", "No docs", ext_methods){ static struct PyModuleDef moduledef = { { { 1, ((void*)0) }
, ((void*)0), 0, ((void*)0), }, "_box", "No docs", -1, ext_methods
, ((void*)0), ((void*)0), ((void*)0), ((void*)0) }; m = PyModule_Create2
(&moduledef, 1013); }
157 if (m == NULL((void*)0))
1
Assuming 'm' is not equal to NULL
2
Taking false branch
158 return MOD_ERROR_VAL((void*)0);
159
160 /* init BoxType */
161 if (PyType_Ready(&BoxType))
3
Assuming the condition is false
4
Taking false branch
162 return MOD_ERROR_VAL((void*)0);
163
164 /* import and cache NRT_MemInfo_release function pointer */
165 MemInfo_release = import_meminfo_release();
166 if (!MemInfo_release) return MOD_ERROR_VAL((void*)0);
5
Assuming 'MemInfo_release' is non-null
6
Taking false branch
167
168 /* bind BoxType */
169 Py_INCREF(&BoxType)_Py_INCREF(((PyObject*)(&BoxType)));
170 PyModule_AddObject(m, "Box", (PyObject *) (&BoxType));
171
172 /* bind address to direct access utils */;
173 PyModule_AddObject(m, "box_meminfoptr_offset",
174 PyLong_FromSsize_t(offsetof(BoxObject, meminfoptr)__builtin_offsetof(BoxObject, meminfoptr)));
175 PyModule_AddObject(m, "box_dataptr_offset",
176 PyLong_FromSsize_t(offsetof(BoxObject, dataptr)__builtin_offsetof(BoxObject, dataptr)));
7
Calling 'PyLong_FromSsize_t'
9
Returning from 'PyLong_FromSsize_t'
10
PyObject ownership leak with reference count of 1
177
178 return MOD_SUCCESS_VAL(m)m;
179}

/opt/pyrefcon/lib/pyrefcon/models/models/PyLong_FromSsize_t.model

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