Bug Summary

File:np/ufunc/_num_threads.c
Warning:line 32, column 28
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 _num_threads.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/np/ufunc/_num_threads.c

numba/np/ufunc/_num_threads.c

1// Thread local num_threads variable for masking out the total number of
2// launched threads.
3
4#include "../../_pymodule.h"
5
6#ifdef _MSC_VER
7#define THREAD_LOCAL(ty)__thread ty __declspec(thread) ty
8#else
9/* Non-standard C99 extension that's understood by gcc and clang */
10#define THREAD_LOCAL(ty)__thread ty __thread ty
11#endif
12
13static THREAD_LOCAL(int)__thread int num_threads = 0;
14
15static void set_num_threads(int count)
16{
17 num_threads = count;
18}
19
20static int get_num_threads(void)
21{
22 return num_threads;
23}
24
25MOD_INIT(_num_threads)PyObject* PyInit__num_threads(void)
26{
27 PyObject *m;
28 MOD_DEF(m, "_num_threads", "No docs", NULL){ static struct PyModuleDef moduledef = { { { 1, ((void*)0) }
, ((void*)0), 0, ((void*)0), }, "_num_threads", "No docs", -1
, ((void*)0), ((void*)0), ((void*)0), ((void*)0), ((void*)0) }
; m = PyModule_Create2(&moduledef, 1013); }
29 if (m == NULL((void*)0))
1
Assuming 'm' is not equal to NULL
2
Taking false branch
30 return MOD_ERROR_VAL((void*)0);
31 PyObject_SetAttrString(m, "set_num_threads",
32 PyLong_FromVoidPtr((void*)&set_num_threads));
3
Calling 'PyLong_FromVoidPtr'
5
Returning from 'PyLong_FromVoidPtr'
6
PyObject ownership leak with reference count of 1
33 PyObject_SetAttrString(m, "get_num_threads",
34 PyLong_FromVoidPtr((void*)&get_num_threads));
35
36 return MOD_SUCCESS_VAL(m)m;
37}

/opt/pyrefcon/lib/pyrefcon/models/models/PyLong_FromVoidPtr.model

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