Bug Summary

File:.cache/bazel/_bazel_alan/39be661231df2a680c9b74265384c13c/execroot/org_tensorflow/tensorflow/python/distribute/parallel_device/pywrap_parallel_device.cc
Warning:line 53, column 15
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 pywrap_parallel_device.cc -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-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/tensorflow/csa-scan,ctu-index-name=/tmp/pyrefcon/tensorflow/csa-scan/externalDefMap.txt,ctu-invocation-list=/tmp/pyrefcon/tensorflow/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=all -relaxed-aliasing -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/home/pyrefcon/.cache/bazel/_bazel_alan/39be661231df2a680c9b74265384c13c/execroot/org_tensorflow -resource-dir /opt/pyrefcon/lib/clang/13.0.0 -iquote . -iquote bazel-out/k8-opt/bin -iquote external/com_google_absl -iquote bazel-out/k8-opt/bin/external/com_google_absl -iquote external/nsync -iquote bazel-out/k8-opt/bin/external/nsync -iquote external/eigen_archive -iquote bazel-out/k8-opt/bin/external/eigen_archive -iquote external/gif -iquote bazel-out/k8-opt/bin/external/gif -iquote external/libjpeg_turbo -iquote bazel-out/k8-opt/bin/external/libjpeg_turbo -iquote external/com_google_protobuf -iquote bazel-out/k8-opt/bin/external/com_google_protobuf -iquote external/com_googlesource_code_re2 -iquote bazel-out/k8-opt/bin/external/com_googlesource_code_re2 -iquote external/farmhash_archive -iquote bazel-out/k8-opt/bin/external/farmhash_archive -iquote external/fft2d -iquote bazel-out/k8-opt/bin/external/fft2d -iquote external/highwayhash -iquote bazel-out/k8-opt/bin/external/highwayhash -iquote external/zlib -iquote bazel-out/k8-opt/bin/external/zlib -iquote external/double_conversion -iquote bazel-out/k8-opt/bin/external/double_conversion -iquote external/pybind11 -iquote bazel-out/k8-opt/bin/external/pybind11 -iquote external/local_config_python -iquote bazel-out/k8-opt/bin/external/local_config_python -iquote external/bazel_tools -iquote bazel-out/k8-opt/bin/external/bazel_tools -isystem external/nsync/public -isystem bazel-out/k8-opt/bin/external/nsync/public -isystem third_party/eigen3/mkl_include -isystem bazel-out/k8-opt/bin/third_party/eigen3/mkl_include -isystem external/eigen_archive -isystem bazel-out/k8-opt/bin/external/eigen_archive -isystem external/gif -isystem bazel-out/k8-opt/bin/external/gif -isystem external/com_google_protobuf/src -isystem bazel-out/k8-opt/bin/external/com_google_protobuf/src -isystem external/farmhash_archive/src -isystem bazel-out/k8-opt/bin/external/farmhash_archive/src -isystem external/zlib -isystem bazel-out/k8-opt/bin/external/zlib -isystem external/double_conversion -isystem bazel-out/k8-opt/bin/external/double_conversion -isystem external/pybind11/include -isystem bazel-out/k8-opt/bin/external/pybind11/include -isystem /opt/pyrefcon/lib/pyrefcon/models/python3.8 -isystem /opt/pyrefcon/lib/pyrefcon/models/python3.8 -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=1 -D NDEBUG -D EIGEN_MPL2_ONLY -D EIGEN_MAX_ALIGN_BYTES=64 -I bazel-out/k8-opt/bin/external/pybind11/_virtual_includes/pybind11 -D AUTOLOAD_DYNAMIC_KERNELS -D __DATE__="redacted" -D __TIMESTAMP__="redacted" -D __TIME__="redacted" -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 -O2 -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -Wno-builtin-macro-redefined -w -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/home/pyrefcon/.cache/bazel/_bazel_alan/39be661231df2a680c9b74265384c13c/execroot/org_tensorflow -ferror-limit 19 -fvisibility hidden -stack-protector 1 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/pyrefcon/tensorflow/csa-scan/reports -x c++ tensorflow/python/distribute/parallel_device/pywrap_parallel_device.cc

tensorflow/python/distribute/parallel_device/pywrap_parallel_device.cc

1/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#include "Python.h"
17#include "pybind11/pybind11.h"
18#include "pybind11/stl.h"
19#include "tensorflow/c/c_api.h"
20#include "tensorflow/c/c_api_experimental.h"
21#include "tensorflow/c/eager/c_api.h"
22#include "tensorflow/c/eager/c_api_experimental.h"
23#include "tensorflow/c/eager/parallel_device/parallel_device.h"
24#include "tensorflow/python/lib/core/py_exception_registry.h"
25#include "tensorflow/python/lib/core/pybind11_lib.h"
26#include "tensorflow/python/lib/core/pybind11_status.h"
27#include "tensorflow/python/lib/core/safe_ptr.h"
28
29namespace py = pybind11;
30
31void CallDelete_Device(PyObject* capsule) {
32 delete reinterpret_cast<TFE_CustomDevice*>(
33 PyCapsule_GetPointer(capsule, "TFE_CustomDevice"));
34}
35
36void CallDelete_DeviceInfo(PyObject* capsule) {
37 void (*destructor)(void*) =
38 reinterpret_cast<void (*)(void*)>(PyCapsule_GetContext(capsule));
39 destructor(PyCapsule_GetPointer(capsule, "TFE_CustomDevice_DeviceInfo"));
40}
41
42PYBIND11_MODULE(_pywrap_parallel_device, m)static ::pybind11::module_::module_def pybind11_module_def__pywrap_parallel_device
; __attribute__ ((__unused__)) static void pybind11_init__pywrap_parallel_device
(::pybind11::module_ &); extern "C" __attribute__ ((__unused__
)) __attribute__ ((visibility("default"))) PyObject *PyInit__pywrap_parallel_device
(); extern "C" __attribute__ ((visibility("default"))) PyObject
*PyInit__pywrap_parallel_device() { { const char *compiled_ver
= "3" "." "8"; const char *runtime_ver = Py_GetVersion(); size_t
len = std::strlen(compiled_ver); if (std::strncmp(runtime_ver
, compiled_ver, len) != 0 || (runtime_ver[len] >= '0' &&
runtime_ver[len] <= '9')) { PyErr_Format(PyExc_ImportError
, "Python version mismatch: module was compiled for Python %s, "
"but the interpreter version is incompatible: %s.", compiled_ver
, runtime_ver); return nullptr; } } pybind11::detail::get_internals
(); auto m = ::pybind11::module_::create_extension_module( "_pywrap_parallel_device"
, nullptr, &pybind11_module_def__pywrap_parallel_device);
try { pybind11_init__pywrap_parallel_device(m); return m.ptr
(); } catch (pybind11::error_already_set &e) { PyErr_SetString
(PyExc_ImportError, e.what()); return nullptr; } catch (const
std::exception &e) { PyErr_SetString(PyExc_ImportError, e
.what()); return nullptr; } } void pybind11_init__pywrap_parallel_device
(::pybind11::module_ &m)
{
43 m.def("GetParallelDeviceCapsules",
44 [](const char* name, std::vector<std::string> underlying_devices) {
45 std::vector<const char*> underlying_devices_c;
46 underlying_devices_c.reserve(underlying_devices.size());
47 for (const std::string& element : underlying_devices) {
48 underlying_devices_c.push_back(element.c_str());
49 }
50 // `device` is owned by `device_capsule`.
51 TFE_CustomDevice* device = new TFE_CustomDevice;
52 tensorflow::Safe_PyObjectPtr device_capsule(
53 PyCapsule_New(device, "TFE_CustomDevice", &CallDelete_Device));
1
Calling 'PyCapsule_New'
3
Returning from 'PyCapsule_New'
6
PyObject ownership leak with reference count of 1
54 void* device_info;
55 tensorflow::parallel_device::AllocateParallelDevice(
56 name, underlying_devices_c.data(), underlying_devices_c.size(),
57 device, &device_info);
58 if (PyErr_Occurred()) throw py::error_already_set();
4
Assuming the condition is true
5
Taking true branch
59 tensorflow::Safe_PyObjectPtr device_info_capsule(
60 PyCapsule_New(device_info, "TFE_CustomDevice_DeviceInfo",
61 &CallDelete_DeviceInfo));
62 if (PyErr_Occurred()) throw py::error_already_set();
63 // The PyCapsule destructor needs a pointer to the destructor for
64 // DeviceInfo.
65 PyCapsule_SetContext(device_info_capsule.get(),
66 reinterpret_cast<void*>(device->delete_device));
67 return tensorflow::PyoOrThrow(
68 PyTuple_Pack(2, device_capsule.get(), device_info_capsule.get()));
69 });
70}

/opt/pyrefcon/lib/pyrefcon/models/models/PyCapsule_New.model

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