diff --git a/libnm-glib/nm-client.c b/libnm-glib/nm-client.c index 161511c844..4e725cf42a 100644 --- a/libnm-glib/nm-client.c +++ b/libnm-glib/nm-client.c @@ -1024,7 +1024,7 @@ client_device_added_proxy (DBusGProxy *proxy, char *path, gpointer user_data) device = G_OBJECT (_nm_object_cache_get (path)); if (device) { - g_ptr_array_add (priv->devices, g_object_ref (device)); + g_ptr_array_add (priv->devices, device); } else { device = G_OBJECT (nm_device_new (connection, path)); if (device) diff --git a/libnm-glib/nm-device-wifi.c b/libnm-glib/nm-device-wifi.c index ebc504bc73..530fa441af 100644 --- a/libnm-glib/nm-device-wifi.c +++ b/libnm-glib/nm-device-wifi.c @@ -393,7 +393,7 @@ access_point_added_proxy (DBusGProxy *proxy, char *path, gpointer user_data) priv = NM_DEVICE_WIFI_GET_PRIVATE (self); ap = G_OBJECT (_nm_object_cache_get (path)); if (ap) { - g_ptr_array_add (priv->aps, g_object_ref (ap)); + g_ptr_array_add (priv->aps, ap); } else { ap = G_OBJECT (nm_access_point_new (connection, path)); if (ap) @@ -567,9 +567,7 @@ demarshal_active_ap (NMObject *object, GParamSpec *pspec, GValue *value, gpointe priv->null_active_ap = TRUE; else { ap = NM_ACCESS_POINT (_nm_object_cache_get (path)); - if (ap) - ap = g_object_ref (ap); - else { + if (!ap) { connection = nm_object_get_connection (object); ap = NM_ACCESS_POINT (nm_access_point_new (connection, path)); } diff --git a/libnm-glib/nm-device-wimax.c b/libnm-glib/nm-device-wimax.c index fd6aff714c..aff1dafe97 100644 --- a/libnm-glib/nm-device-wimax.c +++ b/libnm-glib/nm-device-wimax.c @@ -275,7 +275,7 @@ nsp_added_proxy (DBusGProxy *proxy, char *path, gpointer user_data) priv = NM_DEVICE_WIMAX_GET_PRIVATE (self); nsp = G_OBJECT (_nm_object_cache_get (path)); if (nsp) { - g_ptr_array_add (priv->nsps, g_object_ref (nsp)); + g_ptr_array_add (priv->nsps, nsp); } else { nsp = G_OBJECT (nm_wimax_nsp_new (connection, path)); if (nsp) @@ -601,9 +601,7 @@ demarshal_active_nsp (NMObject *object, GParamSpec *pspec, GValue *value, gpoint priv->null_active_nsp = TRUE; else { nsp = NM_WIMAX_NSP (_nm_object_cache_get (path)); - if (nsp) - nsp = g_object_ref (nsp); - else { + if (!nsp) { connection = nm_object_get_connection (object); nsp = NM_WIMAX_NSP (nm_wimax_nsp_new (connection, path)); } diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c index d1b34cfb2a..f1576e6b92 100644 --- a/libnm-glib/nm-device.c +++ b/libnm-glib/nm-device.c @@ -127,9 +127,7 @@ demarshal_ip4_config (NMObject *object, GParamSpec *pspec, GValue *value, gpoint priv->null_ip4_config = TRUE; else { config = NM_IP4_CONFIG (_nm_object_cache_get (path)); - if (config) - config = g_object_ref (config); - else { + if (!config) { connection = nm_object_get_connection (object); config = NM_IP4_CONFIG (nm_ip4_config_new (connection, path)); } @@ -167,9 +165,7 @@ demarshal_dhcp4_config (NMObject *object, GParamSpec *pspec, GValue *value, gpoi priv->null_dhcp4_config = TRUE; else { config = NM_DHCP4_CONFIG (_nm_object_cache_get (path)); - if (config) - config = g_object_ref (config); - else { + if (!config) { connection = nm_object_get_connection (object); config = NM_DHCP4_CONFIG (nm_dhcp4_config_new (connection, path)); } @@ -207,9 +203,7 @@ demarshal_ip6_config (NMObject *object, GParamSpec *pspec, GValue *value, gpoint priv->null_ip6_config = TRUE; else { config = NM_IP6_CONFIG (_nm_object_cache_get (path)); - if (config) - config = g_object_ref (config); - else { + if (!config) { connection = nm_object_get_connection (object); config = NM_IP6_CONFIG (nm_ip6_config_new (connection, path)); } @@ -247,9 +241,7 @@ demarshal_dhcp6_config (NMObject *object, GParamSpec *pspec, GValue *value, gpoi priv->null_dhcp6_config = TRUE; else { config = NM_DHCP6_CONFIG (_nm_object_cache_get (path)); - if (config) - config = g_object_ref (config); - else { + if (!config) { connection = nm_object_get_connection (object); config = NM_DHCP6_CONFIG (nm_dhcp6_config_new (connection, path)); } diff --git a/libnm-glib/nm-object-cache.c b/libnm-glib/nm-object-cache.c index fdbca00f53..c43b427335 100644 --- a/libnm-glib/nm-object-cache.c +++ b/libnm-glib/nm-object-cache.c @@ -67,6 +67,6 @@ _nm_object_cache_get (const char *path) _init_cache (); object = g_hash_table_lookup (cache, path); - return object; + return object ? g_object_ref (object) : NULL; } diff --git a/libnm-glib/nm-object-cache.h b/libnm-glib/nm-object-cache.h index b8cf2121b6..2348dcfa09 100644 --- a/libnm-glib/nm-object-cache.h +++ b/libnm-glib/nm-object-cache.h @@ -29,6 +29,7 @@ G_BEGIN_DECLS +/* Returns referenced object from the cache */ NMObject *_nm_object_cache_get (const char *path); void _nm_object_cache_add (NMObject *object); void _nm_object_cache_remove_by_object (NMObject *object); diff --git a/libnm-glib/nm-types.c b/libnm-glib/nm-types.c index 923c436b18..a2d6d2b4fc 100644 --- a/libnm-glib/nm-types.c +++ b/libnm-glib/nm-types.c @@ -253,9 +253,9 @@ _nm_object_array_demarshal (GValue *value, path = g_ptr_array_index (array, i); object = G_OBJECT (_nm_object_cache_get (path)); - if (object) { - g_ptr_array_add (temp, g_object_ref (object)); - } else { + if (object) + g_ptr_array_add (temp, object); + else { object = (*func) (connection, path); if (object) g_ptr_array_add (temp, object);