From ffa012f3cef96daead331c6f573e5357d7f0ad85 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Mon, 9 Sep 2013 09:13:41 -0400 Subject: [PATCH] libnm-glib: fix nm_remote_connection_delete() callback If you called nm_remote_connection_delete() on a connection whose only ref was held by the NMRemoteSettings, then the callback would never get called, because NMRemoteSettings would drop its ref before then (when the connection emitted the 'removed' signal), so the callback would get cancelled. Fix this by taking an extra ref on the connection around the D-Bus call in this case. https://bugzilla.redhat.com/show_bug.cgi?id=997568 https://bugzilla.gnome.org/show_bug.cgi?id=706141 --- libnm-glib/nm-remote-connection.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libnm-glib/nm-remote-connection.c b/libnm-glib/nm-remote-connection.c index f72b71e91f..a03a44bf42 100644 --- a/libnm-glib/nm-remote-connection.c +++ b/libnm-glib/nm-remote-connection.c @@ -71,6 +71,7 @@ typedef struct { DBusGProxyCall *call; GFunc callback; gpointer user_data; + gboolean extra_ref; } RemoteCall; typedef struct { @@ -118,6 +119,10 @@ remote_call_complete (NMRemoteConnection *self, RemoteCall *call) NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self); priv->calls = g_slist_remove (priv->calls, call); + + if (call->extra_ref) + g_object_unref (self); + /* Don't need to cancel it since this function should only be called from * the dispose handler (where the proxy will be destroyed immediately after) * or from the call's completion callback. @@ -286,6 +291,14 @@ nm_remote_connection_delete (NMRemoteConnection *self, call->callback = (GFunc) callback; call->user_data = user_data; + if (callback) { + /* Grab an extra ref on @self to make sure it doesn't get + * destroyed by the NMRemoteSettings before the callback runs. + */ + g_object_ref (self); + call->extra_ref = TRUE; + } + call->call = dbus_g_proxy_begin_call (priv->proxy, "Delete", result_cb, call, NULL, G_TYPE_INVALID);