Bug Summary

File:build/temp.linux-x86_64-3.8/../../test/dbus_py_test.c
Warning:line 102, column 18
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 dbus_py_test.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-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/dbus-python/csa-scan,ctu-index-name=/tmp/pyrefcon/dbus-python/csa-scan/externalDefMap.txt,ctu-invocation-list=/tmp/pyrefcon/dbus-python/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 -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/dbus-python/build/temp.linux-x86_64-3.8 -resource-dir /opt/pyrefcon/lib/clang/13.0.0 -include config.h -isystem /opt/pyrefcon/lib/pyrefcon/models/python3.8 -D HAVE_CONFIG_H -I . -I /tmp/pyrefcon/dbus-python -I /tmp/pyrefcon/dbus-python/include -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -D PIC -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 -Wdeprecated-declarations -Wno-declaration-after-statement -Wno-duplicated-branches -Wno-inline -Wno-redundant-decls -Wno-switch-default -Wno-write-strings -Wnested-externs -Wmissing-prototypes -Wstrict-prototypes -Wimplicit-function-declaration -Wold-style-definition -Wjump-misses-init -Wall -Wextra -Wundef -Wpointer-arith -Wmissing-declarations -Wno-unused-parameter -Wno-missing-field-initializers -Wformat=2 -Wcast-align -Wformat-nonliteral -Wformat-security -Wsign-compare -Wstrict-aliasing -Wshadow -Wpacked -Wmissing-format-attribute -Wmissing-noreturn -Winit-self -Wmissing-include-dirs -Wunused-but-set-variable -Warray-bounds -Wreturn-type -Wswitch-enum -Wduplicated-cond -Wlogical-op -Wrestrict -Wnull-dereference -Wdouble-promotion -Wno-error=declaration-after-statement -Wno-error=duplicated-branches -Wno-error=inline -Wno-error=redundant-decls -Wno-error=switch-default -Wno-error=write-strings -Wno-error=unused-parameter -Wno-error=missing-field-initializers -fdebug-compilation-dir=/tmp/pyrefcon/dbus-python/build/temp.linux-x86_64-3.8 -ferror-limit 19 -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/pyrefcon/dbus-python/csa-scan/reports -x c ../../test/dbus_py_test.c

../../test/dbus_py_test.c

1/* Test fixtures for dbus-python, based on _dbus_glib_bindings.
2 *
3 * Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
4 *
5 * SPDX-License-Identifier: MIT
6 *
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use, copy,
11 * modify, merge, publish, distribute, sublicense, and/or sell copies
12 * of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 */
27
28#include <Python.h>
29#include <dbus/dbus-python.h>
30
31PyMODINIT_FUNCPyObject* PyInit_dbus_py_test(void);
32
33#if defined(__GNUC__4)
34# if __GNUC__4 >= 3
35# define UNUSED__attribute__((__unused__)) __attribute__((__unused__))
36# else
37# define UNUSED__attribute__((__unused__)) /*nothing*/
38# endif
39#else
40# define UNUSED__attribute__((__unused__)) /*nothing*/
41#endif
42
43static dbus_bool_t
44dbus_py_test_set_up_conn(DBusConnection *conn UNUSED__attribute__((__unused__)), void *data UNUSED__attribute__((__unused__)))
45{
46 PyErr_SetString(PyExc_ValueError, "Dummy error from UnusableMainLoop");
47 return 0;
48}
49
50static dbus_bool_t
51dbus_py_test_set_up_srv(DBusServer *srv UNUSED__attribute__((__unused__)), void *data UNUSED__attribute__((__unused__)))
52{
53 PyErr_SetString(PyExc_ValueError, "Dummy error from UnusableMainLoop");
54 return 0;
55}
56
57static void
58dbus_py_test_free(void *data UNUSED__attribute__((__unused__)))
59{
60}
61
62static PyObject *
63dbus_test_native_mainloop(void)
64{
65 PyObject *loop = DBusPyNativeMainLoop_New4((PyObject *(*)(_dbus_py_conn_setup_func, _dbus_py_srv_setup_func
, _dbus_py_free_func, void *))dbus_bindings_API[2])
(dbus_py_test_set_up_conn,
66 dbus_py_test_set_up_srv,
67 dbus_py_test_free,
68 NULL((void*)0));
69 return loop;
70}
71
72static PyObject *
73UnusableMainLoop (PyObject *always_null UNUSED__attribute__((__unused__)), PyObject *args, PyObject *kwargs)
74{
75 PyObject *mainloop, *function, *result;
76 int set_as_default = 0;
77 static char *argnames[] = {"set_as_default", NULL((void*)0)};
78
79 if (PyTuple_Size(args) != 0) {
1
Assuming the condition is false
2
Taking false branch
80 PyErr_SetString(PyExc_TypeError, "UnusableMainLoop() takes no "
81 "positional arguments");
82 return NULL((void*)0);
83 }
84 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", argnames,
3
Assuming the condition is false
4
Taking false branch
85 &set_as_default)) {
86 return NULL((void*)0);
87 }
88
89 mainloop = dbus_test_native_mainloop();
90 if (mainloop && set_as_default) {
5
Assuming 'mainloop' is non-null
6
Assuming 'set_as_default' is not equal to 0
7
Taking true branch
91 if (!_dbus_bindings_module) {
8
Assuming '_dbus_bindings_module' is non-null
9
Taking false branch
92 PyErr_SetString(PyExc_ImportError, "_dbus_bindings not imported");
93 Py_CLEAR(mainloop)do { PyObject *_py_tmp = ((PyObject*)(mainloop)); if (_py_tmp
!= ((void*)0)) { (mainloop) = ((void*)0); _Py_DECREF(((PyObject
*)(_py_tmp))); } } while (0)
;
94 return NULL((void*)0);
95 }
96 function = PyObject_GetAttrString(_dbus_bindings_module,
97 "set_default_main_loop");
98 if (!function) {
10
Assuming 'function' is non-null
11
Taking false branch
99 Py_CLEAR(mainloop)do { PyObject *_py_tmp = ((PyObject*)(mainloop)); if (_py_tmp
!= ((void*)0)) { (mainloop) = ((void*)0); _Py_DECREF(((PyObject
*)(_py_tmp))); } } while (0)
;
100 return NULL((void*)0);
101 }
102 result = PyObject_CallFunctionObjArgs(function, mainloop, NULL((void*)0));
12
Calling 'PyObject_CallFunctionObjArgs'
14
Returning from 'PyObject_CallFunctionObjArgs'
19
PyObject ownership leak with reference count of 1
103 Py_CLEAR(function)do { PyObject *_py_tmp = ((PyObject*)(function)); if (_py_tmp
!= ((void*)0)) { (function) = ((void*)0); _Py_DECREF(((PyObject
*)(_py_tmp))); } } while (0)
;
15
Taking true branch
16
Loop condition is false. Exiting loop
104 if (!result) {
17
Assuming 'result' is non-null
18
Taking false branch
105 Py_CLEAR(mainloop)do { PyObject *_py_tmp = ((PyObject*)(mainloop)); if (_py_tmp
!= ((void*)0)) { (mainloop) = ((void*)0); _Py_DECREF(((PyObject
*)(_py_tmp))); } } while (0)
;
106 return NULL((void*)0);
107 }
108 }
109 return mainloop;
110}
111
112static PyMethodDef module_functions[] = {
113 {"UnusableMainLoop", (PyCFunction) (void (*)(void))UnusableMainLoop,
114 METH_VARARGS0x0001|METH_KEYWORDS0x0002, "Return a main loop that fails to attach"},
115 {NULL((void*)0), NULL((void*)0), 0, NULL((void*)0)}
116};
117
118PyMODINIT_FUNCPyObject*
119PyInit_dbus_py_test(void)
120{
121 static struct PyModuleDef moduledef = {
122 PyModuleDef_HEAD_INIT{ { 1, ((void*)0) }, ((void*)0), 0, ((void*)0), },
123 "dbus_py_test", /* m_name */
124 NULL((void*)0), /* m_doc */
125 -1, /* m_size */
126 module_functions, /* m_methods */
127 NULL((void*)0), /* m_reload */
128 NULL((void*)0), /* m_traverse */
129 NULL((void*)0), /* m_clear */
130 NULL((void*)0) /* m_free */
131 };
132 if (import_dbus_bindings("dbus_py_test") < 0)
133 return NULL((void*)0);
134
135 return PyModule_Create(&moduledef)PyModule_Create2(&moduledef, 1013);
136}
137
138/* vim:set ft=c cino< sw=4 sts=4 et: */

/opt/pyrefcon/lib/pyrefcon/models/models/PyObject_CallFunctionObjArgs.model

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