2010-07-24 09:46:27

by Zhenhua Zhang

[permalink] [raw]
Subject: [PATCH] watch: Free service data in service_reply

Avoid the memory leak of server_data.
---
gdbus/watch.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/gdbus/watch.c b/gdbus/watch.c
index 1d479fa..ccdbb64 100644
--- a/gdbus/watch.c
+++ b/gdbus/watch.c
@@ -468,8 +468,10 @@ static void service_reply(DBusPendingCall *call, void *user_data)
dbus_bool_t has_owner;

reply = dbus_pending_call_steal_reply(call);
- if (reply == NULL)
+ if (reply == NULL) {
+ g_free(data);
return;
+ }

dbus_error_init(&error);

@@ -490,6 +492,7 @@ static void service_reply(DBusPendingCall *call, void *user_data)

done:
dbus_message_unref(reply);
+ g_free(data);
}

static void check_service(DBusConnection *connection, const char *name,
--
1.7.0.4



2010-07-25 19:52:50

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH] watch: Free service data in service_reply

Hi,

On Sat, Jul 24, 2010, Zhenhua Zhang wrote:
> Avoid the memory leak of server_data.
> ---
> gdbus/watch.c | 5 ++++-
> 1 files changed, 4 insertions(+), 1 deletions(-)
>
> diff --git a/gdbus/watch.c b/gdbus/watch.c
> index 1d479fa..ccdbb64 100644
> --- a/gdbus/watch.c
> +++ b/gdbus/watch.c
> @@ -468,8 +468,10 @@ static void service_reply(DBusPendingCall *call, void *user_data)
> dbus_bool_t has_owner;
>
> reply = dbus_pending_call_steal_reply(call);
> - if (reply == NULL)
> + if (reply == NULL) {
> + g_free(data);
> return;
> + }
>
> dbus_error_init(&error);
>
> @@ -490,6 +492,7 @@ static void service_reply(DBusPendingCall *call, void *user_data)
>
> done:
> dbus_message_unref(reply);
> + g_free(data);
> }
>
> static void check_service(DBusConnection *connection, const char *name,

Thanks for the patch, but wouldnt't the following be simpler:

--- a/gdbus/watch.c
+++ b/gdbus/watch.c
@@ -533,7 +533,7 @@ static void check_service(DBusConnection *connection, const char *name,
goto done;
}

- dbus_pending_call_set_notify(call, service_reply, data, NULL);
+ dbus_pending_call_set_notify(call, service_reply, data, g_free);

dbus_pending_call_unref(call);


Johan