Bug Summary

File:/tmp/pyrefcon/scipy/scipy/sparse/linalg/dsolve/_superlumodule.c
Warning:line 336, column 9
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 _superlumodule.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/scipy/csa-scan,ctu-index-name=/tmp/pyrefcon/scipy/csa-scan/externalDefMap.txt,ctu-invocation-list=/tmp/pyrefcon/scipy/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/scipy -resource-dir /opt/pyrefcon/lib/clang/13.0.0 -isystem /opt/pyrefcon/lib/pyrefcon/models/python3.8 -D NDEBUG -D _FORTIFY_SOURCE=2 -D NPY_NO_DEPRECATED_API=NPY_1_9_API_VERSION -D NO_ATLAS_INFO=1 -D HAVE_CBLAS -D USE_VENDOR_BLAS=1 -I /usr/local/include -I /usr/include -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/scipy -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/scipy/csa-scan/reports -x c scipy/sparse/linalg/dsolve/_superlumodule.c

scipy/sparse/linalg/dsolve/_superlumodule.c

1/* -*-c-*- */
2/*
3 * _superlu module
4 *
5 * Python interface to SuperLU decompositions.
6 */
7
8/* Copyright 1999 Travis Oliphant
9 *
10 * Permission to copy and modified this file is granted under
11 * the revised BSD license. No warranty is expressed or IMPLIED
12 */
13
14#include <Python.h>
15
16#define PY_ARRAY_UNIQUE_SYMBOL_scipy_sparse_superlu_ARRAY_API _scipy_sparse_superlu_ARRAY_API
17#include <numpy/ndarrayobject.h>
18
19#include "_superluobject.h"
20
21
22/*
23 * NULL-safe deconstruction functions
24 */
25void XDestroy_SuperMatrix_Store(SuperMatrix * A)
26{
27 Destroy_SuperMatrix_Store(A); /* safe as-is */
28 A->Store = NULL((void*)0);
29}
30
31void XDestroy_SuperNode_Matrix(SuperMatrix * A)
32{
33 if (A->Store) {
34 Destroy_SuperNode_Matrix(A);
35 }
36 A->Store = NULL((void*)0);
37}
38
39void XDestroy_CompCol_Matrix(SuperMatrix * A)
40{
41 if (A->Store) {
42 Destroy_CompCol_Matrix(A);
43 }
44 A->Store = NULL((void*)0);
45}
46
47void XDestroy_CompCol_Permuted(SuperMatrix * A)
48{
49 if (A->Store) {
50 Destroy_CompCol_Permuted(A);
51 }
52 A->Store = NULL((void*)0);
53}
54
55void XStatFree(SuperLUStat_t * stat)
56{
57 if (stat->ops) {
58 StatFree(stat);
59 }
60 stat->ops = NULL((void*)0);
61}
62
63
64/*
65 * Data-type dependent implementations for Xgssv and Xgstrf;
66 *
67 * These have to included from separate files because of SuperLU include
68 * structure.
69 */
70
71static PyObject *Py_gssv(PyObject * self, PyObject * args,
72 PyObject * kwdict)
73{
74 volatile PyObject *Py_B = NULL((void*)0);
75 volatile PyArrayObject *Py_X = NULL((void*)0);
76 volatile PyArrayObject *nzvals = NULL((void*)0);
77 volatile PyArrayObject *colind = NULL((void*)0), *rowptr = NULL((void*)0);
78 volatile int N, nnz;
79 volatile int info;
80 volatile int csc = 0;
81 volatile int *perm_r = NULL((void*)0), *perm_c = NULL((void*)0);
82 volatile SuperMatrix A = { 0 }, B = { 0 }, L = { 0 }, U = { 0 };
83 volatile superlu_options_t options = { 0 };
84 volatile SuperLUStat_t stat = { 0 };
85 volatile PyObject *option_dict = NULL((void*)0);
86 volatile int type;
87 volatile jmp_buf *jmpbuf_ptr;
88 SLU_BEGIN_THREADS_DEFvolatile PyThreadState *_save = ((void*)0);
89
90 static char *kwlist[] = {
91 "N", "nnz", "nzvals", "colind", "rowptr", "B", "csc",
92 "options", NULL((void*)0)
93 };
94
95 /* Get input arguments */
96 if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiO!O!O!O|iO", kwlist,
97 &N, &nnz, &PyArray_Type(*(PyTypeObject *)_scipy_sparse_superlu_ARRAY_API[2]), &nzvals,
98 &PyArray_Type(*(PyTypeObject *)_scipy_sparse_superlu_ARRAY_API[2]), &colind, &PyArray_Type(*(PyTypeObject *)_scipy_sparse_superlu_ARRAY_API[2]),
99 &rowptr, &Py_B, &csc, &option_dict)) {
100 return NULL((void*)0);
101 }
102
103 if (!_CHECK_INTEGER(colind)((((PyArray_TYPE((PyArrayObject*)colind)) >= NPY_BYTE) &&
((PyArray_TYPE((PyArrayObject*)colind)) <= NPY_ULONGLONG)
) && PyArray_ITEMSIZE((PyArrayObject*)colind) == sizeof
(int))
|| !_CHECK_INTEGER(rowptr)((((PyArray_TYPE((PyArrayObject*)rowptr)) >= NPY_BYTE) &&
((PyArray_TYPE((PyArrayObject*)rowptr)) <= NPY_ULONGLONG)
) && PyArray_ITEMSIZE((PyArrayObject*)rowptr) == sizeof
(int))
) {
104 PyErr_SetString(PyExc_TypeError,
105 "colind and rowptr must be of type cint");
106 return NULL((void*)0);
107 }
108
109 type = PyArray_TYPE((PyArrayObject*)nzvals);
110 if (!CHECK_SLU_TYPE(type)(type == NPY_FLOAT || type == NPY_DOUBLE || type == NPY_CFLOAT
|| type == NPY_CDOUBLE)
) {
111 PyErr_SetString(PyExc_TypeError,
112 "nzvals is not of a type supported by SuperLU");
113 return NULL((void*)0);
114 }
115
116 if (!set_superlu_options_from_dict((superlu_options_t*)&options, 0,
117 (PyObject*)option_dict, NULL((void*)0), NULL((void*)0))) {
118 return NULL((void*)0);
119 }
120
121 /* Create Space for output */
122 Py_X = (PyArrayObject*)PyArray_FROMANY((*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int,
PyObject *)) _scipy_sparse_superlu_ARRAY_API[69])((PyObject*
)Py_B, (*(PyArray_Descr * (*)(int)) _scipy_sparse_superlu_ARRAY_API
[45])(type), 1, 2, (((0x0002 | 0x0020) & 0x0020) ? (0x0002
| 0x0020) | ((0x0001 | (0x0100 | 0x0400))) : (0x0002 | 0x0020
)), ((void*)0))
123 (PyObject*)Py_B, type, 1, 2,(*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int,
PyObject *)) _scipy_sparse_superlu_ARRAY_API[69])((PyObject*
)Py_B, (*(PyArray_Descr * (*)(int)) _scipy_sparse_superlu_ARRAY_API
[45])(type), 1, 2, (((0x0002 | 0x0020) & 0x0020) ? (0x0002
| 0x0020) | ((0x0001 | (0x0100 | 0x0400))) : (0x0002 | 0x0020
)), ((void*)0))
124 NPY_ARRAY_F_CONTIGUOUS | NPY_ARRAY_ENSURECOPY)(*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int,
PyObject *)) _scipy_sparse_superlu_ARRAY_API[69])((PyObject*
)Py_B, (*(PyArray_Descr * (*)(int)) _scipy_sparse_superlu_ARRAY_API
[45])(type), 1, 2, (((0x0002 | 0x0020) & 0x0020) ? (0x0002
| 0x0020) | ((0x0001 | (0x0100 | 0x0400))) : (0x0002 | 0x0020
)), ((void*)0))
;
125 if (Py_X == NULL((void*)0))
126 return NULL((void*)0);
127
128 if (PyArray_DIM((PyArrayObject*)Py_X, 0) != N) {
129 PyErr_SetString(PyExc_ValueError,
130 "b array has invalid shape");
131 Py_DECREF(Py_X)_Py_DECREF(((PyObject*)(Py_X)));
132 return NULL((void*)0);
133 }
134
135 if (csc) {
136 if (NCFormat_from_spMatrix((SuperMatrix*)&A, N, N, nnz,
137 (PyArrayObject *)nzvals, (PyArrayObject *)colind,
138 (PyArrayObject *)rowptr, type)) {
139 Py_DECREF(Py_X)_Py_DECREF(((PyObject*)(Py_X)));
140 return NULL((void*)0);
141 }
142 }
143 else {
144 if (NRFormat_from_spMatrix((SuperMatrix*)&A, N, N, nnz, (PyArrayObject *)nzvals,
145 (PyArrayObject *)colind, (PyArrayObject *)rowptr,
146 type)) {
147 Py_DECREF(Py_X)_Py_DECREF(((PyObject*)(Py_X)));
148 return NULL((void*)0);
149 }
150 }
151
152 if (DenseSuper_from_Numeric((SuperMatrix*)&B, (PyObject*)Py_X)) {
153 Destroy_SuperMatrix_Store((SuperMatrix*)&A);
154 Py_DECREF(Py_X)_Py_DECREF(((PyObject*)(Py_X)));
155 return NULL((void*)0);
156 }
157
158 /* B and Py_X share same data now but Py_X "owns" it */
159
160 /* Setup options */
161
162 jmpbuf_ptr = (volatile jmp_buf *)superlu_python_jmpbuf();
163 SLU_BEGIN_THREADSdo { if (_save == ((void*)0)) _save = PyEval_SaveThread(); } while
(0)
;
164 if (setjmp(*(jmp_buf*)jmpbuf_ptr)_setjmp (*(jmp_buf*)jmpbuf_ptr)) {
165 SLU_END_THREADSdo { if (_save) { PyEval_RestoreThread((PyThreadState*)_save)
; _save = ((void*)0);} } while (0)
;
166 goto fail;
167 }
168 else {
169 perm_c = intMalloc(N);
170 perm_r = intMalloc(N);
171 StatInit((SuperLUStat_t*)&stat);
172
173 /* Compute direct inverse of sparse Matrix */
174 gssv(type, (superlu_options_t*)&options, (SuperMatrix*)&A, (int*)perm_c, (int*)perm_r,
175 (SuperMatrix*)&L, (SuperMatrix*)&U, (SuperMatrix*)&B, (SuperLUStat_t*)&stat,
176 (int*)&info);
177 SLU_END_THREADSdo { if (_save) { PyEval_RestoreThread((PyThreadState*)_save)
; _save = ((void*)0);} } while (0)
;
178 }
179
180 SUPERLU_FREE((void*)perm_r)superlu_python_module_free((void*)perm_r);
181 SUPERLU_FREE((void*)perm_c)superlu_python_module_free((void*)perm_c);
182 Destroy_SuperMatrix_Store((SuperMatrix*)&A); /* holds just a pointer to the data */
183 Destroy_SuperMatrix_Store((SuperMatrix*)&B);
184 Destroy_SuperNode_Matrix((SuperMatrix*)&L);
185 Destroy_CompCol_Matrix((SuperMatrix*)&U);
186 StatFree((SuperLUStat_t*)&stat);
187
188 return Py_BuildValue("Ni", Py_X, info);
189
190 fail:
191 SUPERLU_FREE((void*)perm_r)superlu_python_module_free((void*)perm_r);
192 SUPERLU_FREE((void*)perm_c)superlu_python_module_free((void*)perm_c);
193 XDestroy_SuperMatrix_Store((SuperMatrix*)&A); /* holds just a pointer to the data */
194 XDestroy_SuperMatrix_Store((SuperMatrix*)&B);
195 XDestroy_SuperNode_Matrix((SuperMatrix*)&L);
196 XDestroy_CompCol_Matrix((SuperMatrix*)&U);
197 XStatFree((SuperLUStat_t*)&stat);
198 Py_XDECREF(Py_X)_Py_XDECREF(((PyObject*)(Py_X)));
199 return NULL((void*)0);
200}
201
202static PyObject *Py_gstrf(PyObject * self, PyObject * args,
203 PyObject * keywds)
204{
205 /* default value for SuperLU parameters */
206 int N, nnz;
207 PyArrayObject *rowind, *colptr, *nzvals;
208 SuperMatrix A = { 0 };
209 PyObject *result;
210 PyObject *py_csc_construct_func = NULL((void*)0);
211 PyObject *option_dict = NULL((void*)0);
212 int type;
213 int ilu = 0;
214
215 static char *kwlist[] = { "N", "nnz", "nzvals", "colind", "rowptr",
216 "csc_construct_func", "options", "ilu",
217 NULL((void*)0)
218 };
219
220 int res =
221 PyArg_ParseTupleAndKeywords(args, keywds, "iiO!O!O!O|Oi", kwlist,
222 &N, &nnz,
223 &PyArray_Type(*(PyTypeObject *)_scipy_sparse_superlu_ARRAY_API[2]), &nzvals,
224 &PyArray_Type(*(PyTypeObject *)_scipy_sparse_superlu_ARRAY_API[2]), &rowind,
225 &PyArray_Type(*(PyTypeObject *)_scipy_sparse_superlu_ARRAY_API[2]), &colptr,
226 &py_csc_construct_func,
227 &option_dict,
228 &ilu);
229
230 if (!res)
231 return NULL((void*)0);
232
233 if (!_CHECK_INTEGER(colptr)((((PyArray_TYPE((PyArrayObject*)colptr)) >= NPY_BYTE) &&
((PyArray_TYPE((PyArrayObject*)colptr)) <= NPY_ULONGLONG)
) && PyArray_ITEMSIZE((PyArrayObject*)colptr) == sizeof
(int))
|| !_CHECK_INTEGER(rowind)((((PyArray_TYPE((PyArrayObject*)rowind)) >= NPY_BYTE) &&
((PyArray_TYPE((PyArrayObject*)rowind)) <= NPY_ULONGLONG)
) && PyArray_ITEMSIZE((PyArrayObject*)rowind) == sizeof
(int))
) {
234 PyErr_SetString(PyExc_TypeError,
235 "rowind and colptr must be of type cint");
236 return NULL((void*)0);
237 }
238
239 type = PyArray_TYPE((PyArrayObject*)nzvals);
240 if (!CHECK_SLU_TYPE(type)(type == NPY_FLOAT || type == NPY_DOUBLE || type == NPY_CFLOAT
|| type == NPY_CDOUBLE)
) {
241 PyErr_SetString(PyExc_TypeError,
242 "nzvals is not of a type supported by SuperLU");
243 return NULL((void*)0);
244 }
245
246 if (NCFormat_from_spMatrix(&A, N, N, nnz, nzvals, rowind, colptr,
247 type)) {
248 goto fail;
249 }
250
251 result = newSuperLUObject(&A, option_dict, type, ilu, py_csc_construct_func);
252 if (result == NULL((void*)0)) {
253 goto fail;
254 }
255
256 /* arrays of input matrix will not be freed */
257 Destroy_SuperMatrix_Store(&A);
258 return result;
259
260 fail:
261 /* arrays of input matrix will not be freed */
262 XDestroy_SuperMatrix_Store(&A);
263 return NULL((void*)0);
264}
265
266static char gssv_doc[] =
267 "Direct inversion of sparse matrix.\n\nX = gssv(A,B) solves A*X = B for X.";
268
269static char gstrf_doc[] = "gstrf(A, ...)\n\
270\n\
271performs a factorization of the sparse matrix A=*(N,nnz,nzvals,rowind,colptr) and \n\
272returns a factored_lu object.\n\
273\n\
274arguments\n\
275---------\n\
276\n\
277Matrix to be factorized is represented as N,nnz,nzvals,rowind,colptr\n\
278 as separate arguments. This is compressed sparse column representation.\n\
279\n\
280N number of rows and columns \n\
281nnz number of non-zero elements\n\
282nzvals non-zero values \n\
283rowind row-index for this column (same size as nzvals)\n\
284colptr index into rowind for first non-zero value in this column\n\
285 size is (N+1). Last value should be nnz. \n\
286\n\
287additional keyword arguments:\n\
288-----------------------------\n\
289options specifies additional options for SuperLU\n\
290 (same keys and values as in superlu_options_t C structure,\n\
291 and additionally 'Relax' and 'PanelSize')\n\
292\n\
293ilu whether to perform an incomplete LU decomposition\n\
294 (default: false)\n\
295";
296
297
298/*
299 * Main SuperLU module
300 */
301
302static PyMethodDef SuperLU_Methods[] = {
303 {"gssv", (PyCFunction) Py_gssv, METH_VARARGS0x0001 | METH_KEYWORDS0x0002,
304 gssv_doc},
305 {"gstrf", (PyCFunction) Py_gstrf, METH_VARARGS0x0001 | METH_KEYWORDS0x0002,
306 gstrf_doc},
307 {NULL((void*)0), NULL((void*)0)}
308};
309
310static struct PyModuleDef moduledef = {
311 PyModuleDef_HEAD_INIT{ { 1, ((void*)0) }, ((void*)0), 0, ((void*)0), },
312 "_superlu",
313 NULL((void*)0),
314 -1,
315 SuperLU_Methods,
316 NULL((void*)0),
317 NULL((void*)0),
318 NULL((void*)0),
319 NULL((void*)0)
320};
321
322PyObject *PyInit__superlu(void)
323{
324 PyObject *m, *d;
325
326 import_array(){if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(
PyExc_ImportError, "numpy.core.multiarray failed to import");
return ((void*)0); } }
;
1
Taking false branch
327
328 if (PyType_Ready(&SuperLUType) < 0) {
2
Assuming the condition is false
3
Taking false branch
329 return NULL((void*)0);
330 }
331
332 if (PyType_Ready(&SuperLUGlobalType) < 0) {
4
Assuming the condition is false
5
Taking false branch
333 return NULL((void*)0);
334 }
335
336 m = PyModule_Create(&moduledef)PyModule_Create2(&moduledef, 1013);
6
Calling 'PyModule_Create2'
8
Returning from 'PyModule_Create2'
11
PyObject ownership leak with reference count of 1
337 d = PyModule_GetDict(m);
338
339 Py_INCREF(&PyArrayFlags_Type)_Py_INCREF(((PyObject*)(&(*(PyTypeObject *)_scipy_sparse_superlu_ARRAY_API
[4]))))
;
340 PyDict_SetItemString(d, "SuperLU",
341 (PyObject *) &SuperLUType);
342
343 if (PyErr_Occurred())
9
Assuming the condition is true
10
Taking true branch
344 Py_FatalError("can't initialize module _superlu");
345
346 return m;
347}

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

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