diff options
author | Dan Williams <dcbw@redhat.com> | 2015-04-23 09:40:42 -0500 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-04-23 19:49:34 +0200 |
commit | 9b07ea77b8ee19671f2b11812529f26cda9751ab (patch) | |
tree | f6ca4b0c2b9026f779a160d4d1083a201e9b2674 /src/nm-dbus-manager.c | |
parent | 72f264ad9bdebe8df89f84a178aefd9e4d8972ce (diff) | |
download | NetworkManager-9b07ea77b8ee19671f2b11812529f26cda9751ab.tar.gz |
dbus-manager: harden registering/unregistering object
Saw some g_warning() about g_object_weak_unref() trying to unref a non
registed reference. While this does not fix it, let's assert that
situation a step earlier to ease debugging.
Also, move g_object_weak_ref() closer to adding the object into the
@exported hash.
[thaller@redhat.com: rewrote commit message, change to register_object()]
Diffstat (limited to 'src/nm-dbus-manager.c')
-rw-r--r-- | src/nm-dbus-manager.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/nm-dbus-manager.c b/src/nm-dbus-manager.c index 8df1165790..b367b82812 100644 --- a/src/nm-dbus-manager.c +++ b/src/nm-dbus-manager.c @@ -891,8 +891,11 @@ nm_dbus_manager_register_object (NMDBusManager *self, g_assert (G_IS_OBJECT (object)); - g_warn_if_fail (g_hash_table_lookup (priv->exported, object) == NULL); + if (g_hash_table_lookup (priv->exported, G_OBJECT (object))) + g_return_if_reached (); + g_hash_table_insert (priv->exported, G_OBJECT (object), g_strdup (path)); + g_object_weak_ref (G_OBJECT (object), (GWeakNotify) object_destroyed, self); if (priv->g_connection) dbus_g_connection_register_g_object (priv->g_connection, path, G_OBJECT (object)); @@ -905,8 +908,6 @@ nm_dbus_manager_register_object (NMDBusManager *self, G_OBJECT (object)); } } - - g_object_weak_ref (G_OBJECT (object), (GWeakNotify) object_destroyed, self); } void @@ -918,7 +919,10 @@ nm_dbus_manager_unregister_object (NMDBusManager *self, gpointer object) g_assert (G_IS_OBJECT (object)); - g_hash_table_remove (NM_DBUS_MANAGER_GET_PRIVATE (self)->exported, G_OBJECT (object)); + if (!g_hash_table_lookup (priv->exported, G_OBJECT (object))) + g_return_if_reached (); + + g_hash_table_remove (priv->exported, G_OBJECT (object)); g_object_weak_unref (G_OBJECT (object), (GWeakNotify) object_destroyed, self); if (priv->g_connection) |