[packages/python-tdbus] Version: 0.11, some memleak fixes
jajcus
jajcus at pld-linux.org
Mon Oct 22 10:16:49 CEST 2018
commit 3db05e761560c63215fc45a793aed2af45410455
Author: Jacek Konieczny <j.konieczny at eggsoft.pl>
Date: Mon Oct 22 10:16:30 2018 +0200
Version: 0.11, some memleak fixes
python-tdbus.spec | 11 ++--
reference_counting.patch | 140 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 146 insertions(+), 5 deletions(-)
---
diff --git a/python-tdbus.spec b/python-tdbus.spec
index d187857..ea26b31 100644
--- a/python-tdbus.spec
+++ b/python-tdbus.spec
@@ -7,13 +7,13 @@
%define module tdbus
Summary: Simple ("trivial") Python bindings for D-BUS
Name: python-%{module}
-Version: 0.10
-Release: 2
+Version: 0.11
+Release: 1
License: MIT
Group: Libraries/Python
-Source0: https://github.com/hmvp/python-tdbus/archive/v0.10/%{name}-%{version}.tar.gz
-# Source0-md5: 6033776d458aae287d2f9d92a801a42d
-Patch0: use_after_free.patch
+Source0: https://github.com/hmvp/python-tdbus/archive/v%{version}/%{name}-%{version}.tar.gz
+# Source0-md5: 51eb65661eafcb56a10326187cd65355
+Patch0: reference_counting.patch
URL: https://github.com/hmvp/python-tdbus
BuildRequires: rpm-pythonprov
BuildRequires: rpmbuild(macros) >= 1.710
@@ -87,6 +87,7 @@ Dokumentacja API %{module}.
%prep
%setup -q
+
%patch0 -p1
%build
diff --git a/reference_counting.patch b/reference_counting.patch
new file mode 100644
index 0000000..589ce97
--- /dev/null
+++ b/reference_counting.patch
@@ -0,0 +1,140 @@
+From 2de3d789e1c488ad730acabd3fc6f4968ac5e27b Mon Sep 17 00:00:00 2001
+From: Jacek Konieczny <jajcus at jajcus.net>
+Date: Mon, 6 Aug 2018 13:19:51 +0200
+Subject: [PATCH] Release references received from PyObject_CallMethod()
+
+This reference leak usually won't hurt, as in most cases it is just
+a reference to the same single Py_None object. The code was still
+wrong, though.
+---
+ lib/tdbus/_tdbus.c | 24 ++++++++++++++++++------
+ 1 file changed, 18 insertions(+), 6 deletions(-)
+
+diff --git a/lib/tdbus/_tdbus.c b/lib/tdbus/_tdbus.c
+index 46ec3db..9cc094b 100644
+--- a/lib/tdbus/_tdbus.c
++++ b/lib/tdbus/_tdbus.c
+@@ -1519,6 +1519,7 @@ static dbus_bool_t
+ _tdbus_add_watch_callback(DBusWatch *watch, void *data)
+ {
+ PyTDBusWatchObject *Pwatch;
++ PyObject *ret;
+
+ if ((Pwatch = dbus_watch_get_data(watch)) == NULL) {
+ if ((Pwatch = PyObject_New(PyTDBusWatchObject, &PyTDBusWatchType)) == NULL)
+@@ -1528,7 +1529,8 @@ _tdbus_add_watch_callback(DBusWatch *watch, void *data)
+ Py_INCREF(Pwatch);
+ dbus_watch_set_data(watch, Pwatch, _tdbus_decref);
+ }
+- PyObject_CallMethod((PyObject *) data, "add_watch", "O", Pwatch);
++ ret = PyObject_CallMethod((PyObject *) data, "add_watch", "O", Pwatch);
++ Py_XDECREF(ret);
+ if (PyErr_Occurred())
+ PyErr_Clear();
+ return TRUE;
+@@ -1538,10 +1540,12 @@ static void
+ _tdbus_remove_watch_callback(DBusWatch *watch, void *data)
+ {
+ PyObject *Pwatch;
++ PyObject *ret;
+
+ Pwatch = dbus_watch_get_data(watch);
+ ASSERT(Pwatch != NULL);
+- PyObject_CallMethod((PyObject *) data, "remove_watch", "O", Pwatch);
++ ret = PyObject_CallMethod((PyObject *) data, "remove_watch", "O", Pwatch);
++ Py_XDECREF(ret);
+ if (PyErr_Occurred())
+ PyErr_Clear();
+ error:
+@@ -1552,10 +1556,12 @@ static void
+ _tdbus_watch_toggled_callback(DBusWatch *watch, void *data)
+ {
+ PyObject *Pwatch;
++ PyObject *ret;
+
+ Pwatch = dbus_watch_get_data(watch);
+ ASSERT(Pwatch != NULL);
+- PyObject_CallMethod((PyObject *) data, "watch_toggled", "O", Pwatch);
++ ret = PyObject_CallMethod((PyObject *) data, "watch_toggled", "O", Pwatch);
++ Py_XDECREF(ret);
+ if (PyErr_Occurred())
+ PyErr_Clear();
+ error:
+@@ -1566,6 +1572,7 @@ static dbus_bool_t
+ _tdbus_add_timeout_callback(DBusTimeout *timeout, void *data)
+ {
+ PyTDBusTimeoutObject *Ptimeout;
++ PyObject *ret;
+
+ if ((Ptimeout = dbus_timeout_get_data(timeout)) == NULL) {
+ if ((Ptimeout = PyObject_New(PyTDBusTimeoutObject, &PyTDBusTimeoutType)) == NULL)
+@@ -1575,7 +1582,8 @@ _tdbus_add_timeout_callback(DBusTimeout *timeout, void *data)
+ Py_INCREF(Ptimeout);
+ dbus_timeout_set_data(timeout, Ptimeout, _tdbus_decref);
+ }
+- PyObject_CallMethod((PyObject *) data, "add_timeout", "O", Ptimeout);
++ ret = PyObject_CallMethod((PyObject *) data, "add_timeout", "O", Ptimeout);
++ Py_XDECREF(ret);
+ if (PyErr_Occurred())
+ PyErr_Clear();
+ return TRUE;
+@@ -1585,10 +1593,12 @@ static void
+ _tdbus_remove_timeout_callback(DBusTimeout *timeout, void *data)
+ {
+ PyObject *Ptimeout;
++ PyObject *ret;
+
+ Ptimeout = dbus_timeout_get_data(timeout);
+ ASSERT(Ptimeout != NULL);
+- PyObject_CallMethod((PyObject *) data, "remove_timeout", "O", Ptimeout);
++ ret = PyObject_CallMethod((PyObject *) data, "remove_timeout", "O", Ptimeout);
++ Py_XDECREF(ret);
+ if (PyErr_Occurred())
+ PyErr_Clear();
+ error:
+@@ -1599,10 +1609,12 @@ static void
+ _tdbus_timeout_toggled_callback(DBusTimeout *timeout, void *data)
+ {
+ PyObject *Ptimeout;
++ PyObject *ret;
+
+ Ptimeout = dbus_timeout_get_data(timeout);
+ ASSERT(Ptimeout != NULL);
+- PyObject_CallMethod((PyObject *) data, "timeout_toggled", "O", Ptimeout);
++ ret = PyObject_CallMethod((PyObject *) data, "timeout_toggled", "O", Ptimeout);
++ Py_XDECREF(ret);
+ if (PyErr_Occurred())
+ PyErr_Clear();
+ error:
+From 3061ba1347f752cae375fb7ac4658d8facabd0a4 Mon Sep 17 00:00:00 2001
+From: Jacek Konieczny <jajcus at jajcus.net>
+Date: Mon, 6 Aug 2018 13:22:51 +0200
+Subject: [PATCH] Don't add unnecessary references in add_*_callback
+
+PyObject_New() gives us existing reference to TDBusWatch and TDBusTimeout objects,
+which we pass to the DBusWatch and DBusTimeout objects. Calling
+Py_INCREF() of those only creates a memory leak.
+---
+ lib/tdbus/_tdbus.c | 2 --
+ 1 file changed, 2 deletions(-)
+
+diff --git a/lib/tdbus/_tdbus.c b/lib/tdbus/_tdbus.c
+index 9cc094b..d3de475 100644
+--- a/lib/tdbus/_tdbus.c
++++ b/lib/tdbus/_tdbus.c
+@@ -1526,7 +1526,6 @@ _tdbus_add_watch_callback(DBusWatch *watch, void *data)
+ return FALSE;
+ Pwatch->watch = watch;
+ Pwatch->data = NULL;
+- Py_INCREF(Pwatch);
+ dbus_watch_set_data(watch, Pwatch, _tdbus_decref);
+ }
+ ret = PyObject_CallMethod((PyObject *) data, "add_watch", "O", Pwatch);
+@@ -1579,7 +1578,6 @@ _tdbus_add_timeout_callback(DBusTimeout *timeout, void *data)
+ return FALSE;
+ Ptimeout->timeout = timeout;
+ Ptimeout->data = NULL;
+- Py_INCREF(Ptimeout);
+ dbus_timeout_set_data(timeout, Ptimeout, _tdbus_decref);
+ }
+ ret = PyObject_CallMethod((PyObject *) data, "add_timeout", "O", Ptimeout);
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/python-tdbus.git/commitdiff/3db05e761560c63215fc45a793aed2af45410455
More information about the pld-cvs-commit
mailing list