Bug Summary

File:/tmp/pyrefcon/scipy/scipy/optimize/_lsap_module.c
Warning:line 121, 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 _lsap_module.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 -I scipy/_lib/src -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 -std=c99 -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/optimize/_lsap_module.c

scipy/optimize/_lsap_module.c

1/*
2Redistribution and use in source and binary forms, with or without
3modification, are permitted provided that the following conditions
4are met:
5
61. Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer.
8
92. Redistributions in binary form must reproduce the above
10 copyright notice, this list of conditions and the following
11 disclaimer in the documentation and/or other materials provided
12 with the distribution.
13
143. Neither the name of the copyright holder nor the names of its
15 contributors may be used to endorse or promote products derived
16 from this software without specific prior written permission.
17
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*/
30
31#include "numpy/arrayobject.h"
32#include "numpy/ndarraytypes.h"
33#include "rectangular_lsap/rectangular_lsap.h"
34
35static PyObject*
36calculate_assignment(PyObject* self, PyObject* args)
37{
38 PyObject* a = NULL((void*)0);
39 PyObject* b = NULL((void*)0);
40 PyObject* result = NULL((void*)0);
41 PyObject* obj_cost = NULL((void*)0);
42 int maximize = 0;
43 if (!PyArg_ParseTuple(args, "Op", &obj_cost, &maximize))
44 return NULL((void*)0);
45
46 PyArrayObject* obj_cont =
47 (PyArrayObject*)PyArray_ContiguousFromAny(obj_cost, NPY_DOUBLE, 0, 0)(*(PyObject * (*)(PyObject *, PyArray_Descr *, int, int, int,
PyObject *)) PyArray_API[69])(obj_cost, (*(PyArray_Descr * (
*)(int)) PyArray_API[45])(NPY_DOUBLE), 0, 0, ((0x0001 | (0x0100
| 0x0400))), ((void*)0))
;
48 if (!obj_cont) {
49 return NULL((void*)0);
50 }
51
52 if (PyArray_NDIM(obj_cont) != 2) {
53 PyErr_Format(PyExc_ValueError,
54 "expected a matrix (2-D array), got a %d array",
55 PyArray_NDIM(obj_cont));
56 goto cleanup;
57 }
58
59 double* cost_matrix = (double*)PyArray_DATA(obj_cont);
60 if (cost_matrix == NULL((void*)0)) {
61 PyErr_SetString(PyExc_TypeError, "invalid cost matrix object");
62 goto cleanup;
63 }
64
65 npy_intp num_rows = PyArray_DIM(obj_cont, 0);
66 npy_intp num_cols = PyArray_DIM(obj_cont, 1);
67 npy_intp dim[1] = { num_rows < num_cols ? num_rows : num_cols };
68 a = PyArray_SimpleNew(1, dim, NPY_INT64)(*(PyObject * (*)(PyTypeObject *, int, npy_intp const *, int,
npy_intp const *, void *, int, int, PyObject *)) PyArray_API
[93])(&(*(PyTypeObject *)PyArray_API[2]), 1, dim, NPY_LONG
, ((void*)0), ((void*)0), 0, 0, ((void*)0))
;
69 if (!a)
70 goto cleanup;
71
72 b = PyArray_SimpleNew(1, dim, NPY_INT64)(*(PyObject * (*)(PyTypeObject *, int, npy_intp const *, int,
npy_intp const *, void *, int, int, PyObject *)) PyArray_API
[93])(&(*(PyTypeObject *)PyArray_API[2]), 1, dim, NPY_LONG
, ((void*)0), ((void*)0), 0, 0, ((void*)0))
;
73 if (!b)
74 goto cleanup;
75
76 int ret = solve_rectangular_linear_sum_assignment(
77 num_rows, num_cols, cost_matrix, maximize,
78 PyArray_DATA((PyArrayObject*)a),
79 PyArray_DATA((PyArrayObject*)b));
80 if (ret == RECTANGULAR_LSAP_INFEASIBLE-1) {
81 PyErr_SetString(PyExc_ValueError, "cost matrix is infeasible");
82 goto cleanup;
83 }
84 else if (ret == RECTANGULAR_LSAP_INVALID-2) {
85 PyErr_SetString(PyExc_ValueError,
86 "matrix contains invalid numeric entries");
87 goto cleanup;
88 }
89
90 result = Py_BuildValue("OO", a, b);
91
92cleanup:
93 Py_XDECREF((PyObject*)obj_cont)_Py_XDECREF(((PyObject*)((PyObject*)obj_cont)));
94 Py_XDECREF(a)_Py_XDECREF(((PyObject*)(a)));
95 Py_XDECREF(b)_Py_XDECREF(((PyObject*)(b)));
96 return result;
97}
98
99static PyMethodDef lsap_module_methods[] = {
100 { "calculate_assignment", calculate_assignment, METH_VARARGS0x0001,
101 "Solves the rectangular linear sum assignment problem." },
102 { NULL((void*)0), NULL((void*)0), 0, NULL((void*)0) }
103};
104
105static struct PyModuleDef moduledef = {
106 PyModuleDef_HEAD_INIT{ { 1, ((void*)0) }, ((void*)0), 0, ((void*)0), },
107 "_lsap_module",
108 "Solves the rectangular linear sum assignment.",
109 -1,
110 lsap_module_methods,
111 NULL((void*)0),
112 NULL((void*)0),
113 NULL((void*)0),
114 NULL((void*)0),
115};
116
117PyObject*
118PyInit__lsap_module(void)
119{
120 PyObject* m;
121 m = PyModule_Create(&moduledef)PyModule_Create2(&moduledef, 1013);
1
Calling 'PyModule_Create2'
3
Returning from 'PyModule_Create2'
5
PyObject ownership leak with reference count of 1
122 import_array(){if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(
PyExc_ImportError, "numpy.core.multiarray failed to import");
return ((void*)0); } }
;
4
Taking true branch
123 return m;
124}

/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();
2
Setting reference count to 1
7}
8#else
9#warning "API PyModule_Create2 is defined as a macro."
10#endif