Bug Summary

File:build/temp.linux-x86_64-3.8/../../dbus_bindings/mainloop.c
Warning:line 160, 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 mainloop.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 ../../dbus_bindings/mainloop.c

../../dbus_bindings/mainloop.c

1/* Implementation of main-loop integration for dbus-python.
2 *
3 * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/>
4 * Copyright (C) 2008 Huang Peng <phuang@redhat.com>
5 *
6 * SPDX-License-Identifier: MIT
7 *
8 * Permission is hereby granted, free of charge, to any person
9 * obtaining a copy of this software and associated documentation
10 * files (the "Software"), to deal in the Software without
11 * restriction, including without limitation the rights to use, copy,
12 * modify, merge, publish, distribute, sublicense, and/or sell copies
13 * of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 */
28
29#include "dbus_bindings-internal.h"
30
31/* Native mainloop wrapper ========================================= */
32
33PyDoc_STRVAR(NativeMainLoop_tp_doc,static const char NativeMainLoop_tp_doc[] = "Object representing D-Bus main loop integration done in native code.\n"
"Cannot be instantiated directly.\n"
34"Object representing D-Bus main loop integration done in native code.\n"static const char NativeMainLoop_tp_doc[] = "Object representing D-Bus main loop integration done in native code.\n"
"Cannot be instantiated directly.\n"
35"Cannot be instantiated directly.\n"static const char NativeMainLoop_tp_doc[] = "Object representing D-Bus main loop integration done in native code.\n"
"Cannot be instantiated directly.\n"
36)static const char NativeMainLoop_tp_doc[] = "Object representing D-Bus main loop integration done in native code.\n"
"Cannot be instantiated directly.\n"
;
37
38static PyTypeObject NativeMainLoop_Type;
39
40DEFINE_CHECK(NativeMainLoop)static inline int NativeMainLoop_Check (PyObject *o) { return
(((((PyObject*)(o))->ob_type) == (&NativeMainLoop_Type
) || PyType_IsSubtype((((PyObject*)(o))->ob_type), (&NativeMainLoop_Type
)))); } static inline int NativeMainLoop_CheckExact (PyObject
*o) { return ((((PyObject*)(o))->ob_type) == &NativeMainLoop_Type
); }
41
42typedef struct {
43 PyObject_HEADPyObject ob_base;
44 /* Called with the GIL held, should set a Python exception on error */
45 dbus_bool_t (*set_up_connection_cb)(DBusConnection *, void *);
46 dbus_bool_t (*set_up_server_cb)(DBusServer *, void *);
47 /* Called in a destructor. Must not touch the exception state (use
48 * PyErr_Fetch and PyErr_Restore if necessary). */
49 void (*free_cb)(void *);
50 void *data;
51} NativeMainLoop;
52
53static void NativeMainLoop_tp_dealloc(NativeMainLoop *self)
54{
55 if (self->data && self->free_cb) {
56 (self->free_cb)(self->data);
57 }
58 PyObject_DelPyObject_Free((PyObject *)self);
59}
60
61static PyTypeObject NativeMainLoop_Type = {
62 PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0){ { 1, 0 }, 0 },
63 "dbus.mainloop.NativeMainLoop",
64 sizeof(NativeMainLoop),
65 0,
66 (destructor)NativeMainLoop_tp_dealloc, /* tp_dealloc */
67 0, /* tp_print */
68 0, /* tp_getattr */
69 0, /* tp_setattr */
70 0, /* tp_compare */
71 0, /* tp_repr */
72 0, /* tp_as_number */
73 0, /* tp_as_sequence */
74 0, /* tp_as_mapping */
75 0, /* tp_hash */
76 0, /* tp_call */
77 0, /* tp_str */
78 0, /* tp_getattro */
79 0, /* tp_setattro */
80 0, /* tp_as_buffer */
81 Py_TPFLAGS_DEFAULT( 0 | (1UL << 18) | 0), /* tp_flags */
82 NativeMainLoop_tp_doc, /* tp_doc */
83 0, /* tp_traverse */
84 0, /* tp_clear */
85 0, /* tp_richcompare */
86 0, /* tp_weaklistoffset */
87 0, /* tp_iter */
88 0, /* tp_iternext */
89 0, /* tp_methods */
90 0, /* tp_members */
91 0, /* tp_getset */
92 0, /* tp_base */
93 0, /* tp_dict */
94 0, /* tp_descr_get */
95 0, /* tp_descr_set */
96 0, /* tp_dictoffset */
97 0, /* tp_init */
98 0, /* tp_alloc */
99 /* deliberately not callable! */
100 0, /* tp_new */
101};
102
103/* Internal C API for Connection, Bus, Server ======================= */
104
105dbus_bool_t
106dbus_py_check_mainloop_sanity(PyObject *mainloop)
107{
108 if (NativeMainLoop_Check(mainloop)) {
109 return TRUE1;
110 }
111 PyErr_SetString(PyExc_TypeError,
112 "A dbus.mainloop.NativeMainLoop instance is required");
113 return FALSE0;
114}
115
116dbus_bool_t
117dbus_py_set_up_connection(PyObject *conn, PyObject *mainloop)
118{
119 if (NativeMainLoop_Check(mainloop)) {
120 /* Native mainloops are allowed to do arbitrary strange things */
121 NativeMainLoop *nml = (NativeMainLoop *)mainloop;
122 DBusConnection *dbc = DBusPyConnection_BorrowDBusConnection(conn);
123
124 if (!dbc) {
125 return FALSE0;
126 }
127 return (nml->set_up_connection_cb)(dbc, nml->data);
128 }
129 PyErr_SetString(PyExc_TypeError,
130 "A dbus.mainloop.NativeMainLoop instance is required");
131 return FALSE0;
132}
133
134dbus_bool_t
135dbus_py_set_up_server(PyObject *server, PyObject *mainloop)
136{
137 if (NativeMainLoop_Check(mainloop)) {
138 /* Native mainloops are allowed to do arbitrary strange things */
139 NativeMainLoop *nml = (NativeMainLoop *)mainloop;
140 DBusServer *dbs = DBusPyServer_BorrowDBusServer(server);
141
142 if (!dbs) {
143 return FALSE0;
144 }
145 return (nml->set_up_server_cb)(dbs, nml->data);
146 }
147 PyErr_SetString(PyExc_TypeError,
148 "A dbus.mainloop.NativeMainLoop instance is required");
149 return FALSE0;
150}
151
152/* C API ============================================================ */
153
154PyObject *
155DBusPyNativeMainLoop_New4(dbus_bool_t (*conn_cb)(DBusConnection *, void *),
156 dbus_bool_t (*server_cb)(DBusServer *, void *),
157 void (*free_cb)(void *),
158 void *data)
159{
160 NativeMainLoop *self = PyObject_New(NativeMainLoop, &NativeMainLoop_Type)( (NativeMainLoop *) _PyObject_New(&NativeMainLoop_Type) );
2
Calling '_PyObject_New'
4
Returning from '_PyObject_New'
10
PyObject ownership leak with reference count of 1
161 if (self) {
5
Assuming 'self' is non-null
6
Taking true branch
162 self->data = data;
163 self->free_cb = free_cb;
164 self->set_up_connection_cb = conn_cb;
165 self->set_up_server_cb = server_cb;
166 }
167 return (PyObject *)self;
168}
169
170/* Null mainloop implementation ===================================== */
171
172static dbus_bool_t
173noop_main_loop_cb(void *conn_or_server UNUSED__attribute__((__unused__)), void *data UNUSED__attribute__((__unused__)))
174{
175 return TRUE1;
176}
177
178#define noop_conn_cb((dbus_bool_t (*)(DBusConnection *, void *))(noop_main_loop_cb
))
((dbus_bool_t (*)(DBusConnection *, void *))(noop_main_loop_cb))
179#define noop_server_cb((dbus_bool_t (*)(DBusServer *, void *))(noop_main_loop_cb)) ((dbus_bool_t (*)(DBusServer *, void *))(noop_main_loop_cb))
180
181/* Initialization =================================================== */
182
183dbus_bool_t
184dbus_py_init_mainloop(void)
185{
186 if (PyType_Ready (&NativeMainLoop_Type) < 0) return 0;
187
188 return 1;
189}
190
191dbus_bool_t
192dbus_py_insert_mainloop_types(PyObject *this_module)
193{
194 PyObject *null_main_loop = DBusPyNativeMainLoop_New4(noop_conn_cb((dbus_bool_t (*)(DBusConnection *, void *))(noop_main_loop_cb
))
,
1
Calling 'DBusPyNativeMainLoop_New4'
7
Returning from 'DBusPyNativeMainLoop_New4'
195 noop_server_cb((dbus_bool_t (*)(DBusServer *, void *))(noop_main_loop_cb)),
196 NULL((void*)0),
197 NULL((void*)0));
198 if (!null_main_loop
7.1
'null_main_loop' is non-null
7.1
'null_main_loop' is non-null
) return 0;
8
Taking false branch
199
200 /* PyModule_AddObject steals a ref */
201 Py_INCREF (&NativeMainLoop_Type)_Py_INCREF(((PyObject*)(&NativeMainLoop_Type)));
202 if (PyModule_AddObject (this_module, "NativeMainLoop",
9
Taking true branch
203 (PyObject *)&NativeMainLoop_Type) < 0) return 0;
204 if (PyModule_AddObject (this_module, "NULL_MAIN_LOOP",
205 null_main_loop) < 0) return 0;
206 return 1;
207}
208
209/* vim:set ft=c cino< sw=4 sts=4 et: */

/opt/pyrefcon/lib/pyrefcon/models/models/_PyObject_New.model

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