From 3483c36953869114dcce67d2792745707ab63368 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 20 Mar 2014 12:51:18 +0000 Subject: [PATCH 2/3] fix memory leaks: dbus_g_method_get_sender returns a copy We were semi-consistently using it wrong. --- src/mcd-dispatch-operation.c | 12 ++++++------ src/mcd-dispatcher.c | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/mcd-dispatch-operation.c b/src/mcd-dispatch-operation.c index 8df17cb..010bb11 100644 --- a/src/mcd-dispatch-operation.c +++ b/src/mcd-dispatch-operation.c @@ -521,10 +521,7 @@ _mcd_dispatch_operation_check_client_locks (McdDispatchOperation *self) /* if we've been claimed, respond, then do not call HandleChannels */ if (approval != NULL && approval->type == APPROVAL_TYPE_CLAIM) { - /* this needs to be copied because we don't use it til after we've - * freed approval->context */ - gchar *caller = g_strdup (dbus_g_method_get_sender ( - approval->context)); + gchar *caller = dbus_g_method_get_sender (approval->context); /* remove this approval from the list, so it won't be treated as a * failure */ @@ -827,13 +824,16 @@ _mcd_dispatch_operation_finish (McdDispatchOperation *operation, approval != NULL; approval = g_queue_pop_head (priv->approvals)) { + gchar *caller; + switch (approval->type) { case APPROVAL_TYPE_CLAIM: /* someone else got it - either another Claim() or a handler */ g_assert (approval->context != NULL); - DEBUG ("denying Claim call from %s", - dbus_g_method_get_sender (approval->context)); + caller = dbus_g_method_get_sender (approval->context); + DEBUG ("denying Claim call from %s", caller); + g_free (caller); dbus_g_method_return_error (approval->context, priv->result); approval->context = NULL; break; diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c index 5fea7f2..2fc0828 100644 --- a/src/mcd-dispatcher.c +++ b/src/mcd-dispatcher.c @@ -2123,7 +2123,7 @@ dispatcher_delegate_channels ( { McdDispatcher *self = (McdDispatcher *) iface; GError *error = NULL; - const gchar *sender; + gchar *sender = NULL; McdConnection *conn = NULL; DelegateChannelsCtx *ctx = NULL; McdAccountManager *am; @@ -2208,11 +2208,13 @@ dispatcher_delegate_channels ( try_delegating (to_delegate); } + g_free (sender); g_object_unref (am); return; error: + g_free (sender); dbus_g_method_return_error (context, error); g_error_free (error); -- 1.9.1