[patch] python-dbus 0.80.1 memory leak issue

John (J5) Palmieri johnp at redhat.com
Wed Jan 31 08:58:51 PST 2007


On Wed, 2007-01-31 at 13:53 +0000, Simon McVittie wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On Tue, 30 Jan 2007 at 23:42:53 +0100, Luka Renko wrote:
> > I am one of the developers of KDE Guidance Power Manager that uses python-dbus 
> > to access HAL for power management (battery, suspend/hibernate, CPU freq 
> > scaling). By recent upgrade of python-dbus in Kubuntu Feisty to python-dbus 
> > 0.80.1 we have got several user complaints about huge memory consumption of 
> > our application. Memory was used in the range of 0.5 MB/minute. See bug [1] 
> > for more details.
> 
> The patch below should fix that. J5: review please? If you approve, I'll do
> a 0.80.2 release with this change.
> 
> Also available in <http://people.freedesktop.org/~smcv/git/dbus-python/.git>
> 
> 	Simon
> 
> - From 99e0758b1d4f958e5753d51e843f1254e15b93b2 Mon Sep 17 00:00:00 2001
> From: Simon McVittie <simon.mcvittie at collabora.co.uk>
> Date: Wed, 31 Jan 2007 13:47:49 +0000
> Subject: [PATCH] _dbus_bindings/pending-call.c: Fix memory leak of one Message per method call.
> Also fix a leak of references to Py_None (unlikely to be a practical problem,
> but best to be correct).
> - ---
>  _dbus_bindings/pending-call.c |    5 +++--
>  1 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/_dbus_bindings/pending-call.c b/_dbus_bindings/pending-call.c
> index b9b7bc1..73071c3 100644
> - --- a/_dbus_bindings/pending-call.c
> +++ b/_dbus_bindings/pending-call.c
> @@ -111,13 +111,14 @@ _pending_call_notify_function(DBusPendingCall *pc,
>                  PyErr_Print();
>              }
>              Py_XDECREF(ret);
> +            Py_DECREF(msg_obj);
>          }
>          /* else OOM has happened - not a lot we can do about that,
>           * except possibly making it fatal (FIXME?) */
>      }
>  
> - -    Py_XDECREF(handler);
>  release:
> +    Py_XDECREF(handler);
This looks wrong

>From above:

    if (!handler) {
        PyErr_Print();
        goto release;
    }

    if (handler == Py_None) {
        /* We've already called (and thrown away) the callback */
        goto release;
    }

The first goto will call Py_XDECREF(handler) on a NULL.  Does Py_XDECREF
handle NULL's as noops?

-- 
John (J5) Palmieri <johnp at redhat.com>



More information about the dbus mailing list