Bug Summary

File:build/../torch/csrc/utils/tensor_memoryformats.cpp
Warning:line 26, column 36
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 tensor_memoryformats.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -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-inlined-defensive-checks=false,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/pytorch/csa-scan,ctu-index-name=/tmp/pyrefcon/pytorch/csa-scan/externalDefMap.txt,ctu-invocation-list=/tmp/pyrefcon/pytorch/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 -relaxed-aliasing -fno-rounding-math -ffp-exception-behavior=ignore -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/tmp/pyrefcon/pytorch/build -resource-dir /opt/pyrefcon/lib/clang/13.0.0 -isystem third_party/gloo -isystem ../cmake/../third_party/gloo -isystem ../cmake/../third_party/googletest/googlemock/include -isystem ../cmake/../third_party/googletest/googletest/include -isystem ../third_party/protobuf/src -isystem ../third_party/gemmlowp -isystem ../third_party/neon2sse -isystem ../third_party/XNNPACK/include -isystem ../third_party -isystem ../cmake/../third_party/eigen -isystem /opt/pyrefcon/lib/pyrefcon/models/python3.8 -isystem /usr/lib/python3/dist-packages/numpy/core/include -isystem ../cmake/../third_party/pybind11/include -isystem /usr/lib/x86_64-linux-gnu/openmpi/include/openmpi -isystem /usr/lib/x86_64-linux-gnu/openmpi/include -isystem ../third_party/ideep/mkl-dnn/include -isystem ../third_party/ideep/include -D BUILDING_TESTS -D FMT_HEADER_ONLY=1 -D HAVE_MALLOC_USABLE_SIZE=1 -D HAVE_MMAP=1 -D HAVE_SHM_OPEN=1 -D HAVE_SHM_UNLINK=1 -D MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS -D ONNXIFI_ENABLE_EXT=1 -D ONNX_ML=1 -D ONNX_NAMESPACE=onnx_torch -D THP_BUILD_MAIN_LIB -D USE_C10D -D USE_C10D_GLOO -D USE_C10D_MPI -D USE_DISTRIBUTED -D USE_EXTERNAL_MZCRC -D USE_NUMPY -D USE_RPC -D USE_TENSORPIPE -D USE_VALGRIND -D _FILE_OFFSET_BITS=64 -D torch_python_EXPORTS -I aten/src -I ../aten/src -I . -I ../ -I ../cmake/../third_party/benchmark/include -I caffe2/contrib/aten -I ../third_party/onnx -I third_party/onnx -I ../third_party/foxi -I third_party/foxi -I ../torch/.. -I ../torch/../aten/src -I ../torch/../aten/src/TH -I caffe2/aten/src -I third_party -I ../torch/../third_party/valgrind-headers -I ../torch/../third_party/gloo -I ../torch/../third_party/onnx -I ../torch/csrc -I ../torch/csrc/api/include -I ../torch/lib -I ../torch/lib/libshm -I ../torch/csrc/distributed -I ../torch/csrc/api -I ../c10/.. -I third_party/ideep/mkl-dnn/include -I ../third_party/ideep/mkl-dnn/src/../include -I ../torch/lib/libshm/../../../torch/lib -I ../third_party/fmt/include -D USE_PTHREADPOOL -D NDEBUG -D USE_KINETO -D LIBKINETO_NOCUPTI -D USE_FBGEMM -D USE_QNNPACK -D USE_PYTORCH_QNNPACK -D USE_XNNPACK -D SYMBOLICATE_MOBILE_DEBUG_HANDLE -D HAVE_AVX_CPU_DEFINITION -D HAVE_AVX2_CPU_DEFINITION -D NDEBUG -D NDEBUG -D CAFFE2_USE_GLOO -D HAVE_GCC_GET_CPUID -D USE_AVX -D USE_AVX2 -D TH_HAVE_THREAD -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -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 -O3 -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -Wno-unused-but-set-variable -Wno-maybe-uninitialized -Werror=format -Werror=cast-function-type -Wno-stringop-overflow -Wno-write-strings -Wno-strict-aliasing -w -std=gnu++14 -fdeprecated-macro -fdebug-compilation-dir=/tmp/pyrefcon/pytorch/build -ferror-limit 19 -fvisibility-inlines-hidden -fopenmp -fopenmp-cuda-parallel-target-regions -pthread -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -faligned-allocation -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/pyrefcon/pytorch/csa-scan/reports -x c++ ../torch/csrc/utils/tensor_memoryformats.cpp

../torch/csrc/utils/tensor_memoryformats.cpp

1#include <torch/csrc/utils/tensor_memoryformats.h>
2
3#include <torch/csrc/DynamicTypes.h>
4#include <torch/csrc/Exceptions.h>
5#include <torch/csrc/MemoryFormat.h>
6#include <c10/core/MemoryFormat.h>
7
8#include <torch/csrc/python_headers.h>
9#include <torch/csrc/utils/object_ptr.h>
10
11
12namespace torch {
13namespace utils {
14
15#define _ADD_MEMORY_FORMAT(format, name){ std::string module_name = "torch."; PyObject* memory_format
= THPMemoryFormat_New(format, module_name + name); _Py_INCREF
(((PyObject*)(memory_format))); if (PyModule_AddObject(torch_module
, name, memory_format) != 0) { throw python_error(); } }
\
16 { \
17 std::string module_name = "torch."; \
18 PyObject* memory_format = THPMemoryFormat_New(format, module_name + name); \
19 Py_INCREF(memory_format)_Py_INCREF(((PyObject*)(memory_format))); \
20 if (PyModule_AddObject(torch_module, name, memory_format) != 0) { \
21 throw python_error(); \
22 } \
23 }
24
25void initializeMemoryFormats() {
26 auto torch_module = THPObjectPtr(PyImport_ImportModule("torch"));
1
Calling 'PyImport_ImportModule'
3
Returning from 'PyImport_ImportModule'
7
PyObject ownership leak with reference count of 1
27 if (!torch_module) {
4
Assuming the condition is false
5
Taking false branch
28 throw python_error();
29 }
30
31 _ADD_MEMORY_FORMAT(at::MemoryFormat::Preserve, "preserve_format"){ std::string module_name = "torch."; PyObject* memory_format
= THPMemoryFormat_New(at::MemoryFormat::Preserve, module_name
+ "preserve_format"); _Py_INCREF(((PyObject*)(memory_format)
)); if (PyModule_AddObject(torch_module, "preserve_format", memory_format
) != 0) { throw python_error(); } }
;
6
Taking true branch
32 _ADD_MEMORY_FORMAT(at::MemoryFormat::Contiguous, "contiguous_format"){ std::string module_name = "torch."; PyObject* memory_format
= THPMemoryFormat_New(at::MemoryFormat::Contiguous, module_name
+ "contiguous_format"); _Py_INCREF(((PyObject*)(memory_format
))); if (PyModule_AddObject(torch_module, "contiguous_format"
, memory_format) != 0) { throw python_error(); } }
;
33 _ADD_MEMORY_FORMAT(at::MemoryFormat::ChannelsLast, "channels_last"){ std::string module_name = "torch."; PyObject* memory_format
= THPMemoryFormat_New(at::MemoryFormat::ChannelsLast, module_name
+ "channels_last"); _Py_INCREF(((PyObject*)(memory_format)))
; if (PyModule_AddObject(torch_module, "channels_last", memory_format
) != 0) { throw python_error(); } }
;
34 _ADD_MEMORY_FORMAT(at::MemoryFormat::ChannelsLast3d, "channels_last_3d"){ std::string module_name = "torch."; PyObject* memory_format
= THPMemoryFormat_New(at::MemoryFormat::ChannelsLast3d, module_name
+ "channels_last_3d"); _Py_INCREF(((PyObject*)(memory_format
))); if (PyModule_AddObject(torch_module, "channels_last_3d",
memory_format) != 0) { throw python_error(); } }
;
35
36}
37
38} // namespace utils
39} // namespace torch

/opt/pyrefcon/lib/pyrefcon/models/models/PyImport_ImportModule.model

1#ifndef PyImport_ImportModule
2struct _object;
3typedef struct _object PyObject;
4PyObject* clang_analyzer_PyObject_New_Reference();
5PyObject* PyImport_ImportModule(const char *name) {
6 return clang_analyzer_PyObject_New_Reference();
2
Setting reference count to 1
7}
8#else
9#warning "API PyImport_ImportModule is defined as a macro."
10#endif