[network-manager-applet/dcbw/fixes: 2/3] editor: clean up object dispose()



commit 022f25a96b5cb2972ec6f9315339ad945d460df8
Author: Dan Williams <dcbw redhat com>
Date:   Fri Oct 10 10:27:52 2014 -0500

    editor: clean up object dispose()
    
    Remove unused 'disposed' private variables and make every dispose()
    safe to be called multiple times.

 src/connection-editor/ce-page.c             |   20 ++++----------------
 src/connection-editor/ce-page.h             |    2 --
 src/connection-editor/ce-polkit-button.c    |   18 +++++++-----------
 src/connection-editor/page-8021x-security.c |   11 +++--------
 src/connection-editor/page-dsl.c            |    2 --
 src/connection-editor/page-ethernet.c       |    2 --
 src/connection-editor/page-general.c        |   12 +++---------
 src/connection-editor/page-ip4.c            |    5 ++---
 src/connection-editor/page-ip6.c            |    5 ++---
 src/connection-editor/page-mobile.c         |    8 +-------
 src/connection-editor/page-ppp.c            |   11 +++--------
 src/connection-editor/page-vpn.c            |   13 ++-----------
 src/connection-editor/page-wifi-security.c  |    9 +--------
 src/connection-editor/page-wifi-security.h  |    1 -
 src/connection-editor/page-wifi.c           |    1 -
 src/connection-editor/page-wimax.c          |    2 --
 16 files changed, 28 insertions(+), 94 deletions(-)
---
diff --git a/src/connection-editor/ce-page.c b/src/connection-editor/ce-page.c
index c63a752..001af30 100644
--- a/src/connection-editor/ce-page.c
+++ b/src/connection-editor/ce-page.c
@@ -374,22 +374,10 @@ dispose (GObject *object)
 {
        CEPage *self = CE_PAGE (object);
 
-       if (self->disposed)
-               return;
-
-       self->disposed = TRUE;
-
-       if (self->page)
-               g_object_unref (self->page);
-
-       if (self->builder)
-               g_object_unref (self->builder);
-
-       if (self->proxy)
-               g_object_unref (self->proxy);
-
-       if (self->connection)
-               g_object_unref (self->connection);
+       g_clear_object (&self->page);
+       g_clear_object (&self->builder);
+       g_clear_object (&self->proxy);
+       g_clear_object (&self->connection);
 
        G_OBJECT_CLASS (ce_page_parent_class)->dispose (object);
 }
diff --git a/src/connection-editor/ce-page.h b/src/connection-editor/ce-page.h
index 9d53320..639beb3 100644
--- a/src/connection-editor/ce-page.h
+++ b/src/connection-editor/ce-page.h
@@ -76,8 +76,6 @@ typedef struct {
        GtkWindow *parent_window;
        NMClient *client;
        NMRemoteSettings *settings;
-
-       gboolean disposed;
 } CEPage;
 
 typedef struct {
diff --git a/src/connection-editor/ce-polkit-button.c b/src/connection-editor/ce-polkit-button.c
index e2701f3..892311a 100644
--- a/src/connection-editor/ce-polkit-button.c
+++ b/src/connection-editor/ce-polkit-button.c
@@ -32,8 +32,6 @@ G_DEFINE_TYPE (CEPolkitButton, ce_polkit_button, GTK_TYPE_BUTTON)
 #define CE_POLKIT_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CE_TYPE_POLKIT_BUTTON, 
CEPolkitButtonPrivate))
 
 typedef struct {
-       gboolean disposed;
-
        char *tooltip;
        char *auth_tooltip;
        gboolean master_sensitive;
@@ -190,17 +188,15 @@ dispose (GObject *object)
 {
        CEPolkitButtonPrivate *priv = CE_POLKIT_BUTTON_GET_PRIVATE (object);
 
-       if (priv->disposed == FALSE) {
-               priv->disposed = TRUE;
-
-               if (priv->perm_id)
-                       g_signal_handler_disconnect (priv->client, priv->perm_id);
-
-               g_object_unref (priv->client);
-               g_object_unref (priv->auth);
-               g_object_unref (priv->stock);
+       if (priv->perm_id) {
+               g_signal_handler_disconnect (priv->client, priv->perm_id);
+               priv->perm_id = 0;
        }
 
+       g_clear_object (&priv->client);
+       g_clear_object (&priv->auth);
+       g_clear_object (&priv->stock);
+
        G_OBJECT_CLASS (ce_polkit_button_parent_class)->dispose (object);
 }
 
diff --git a/src/connection-editor/page-8021x-security.c b/src/connection-editor/page-8021x-security.c
index 62a8e84..5aca1e3 100644
--- a/src/connection-editor/page-8021x-security.c
+++ b/src/connection-editor/page-8021x-security.c
@@ -49,8 +49,6 @@ typedef struct {
        WirelessSecurity *security;
 
        gboolean initial_have_8021x;
-
-       gboolean disposed;
 } CEPage8021xSecurityPrivate;
 
 static void
@@ -195,13 +193,10 @@ dispose (GObject *object)
 {
        CEPage8021xSecurityPrivate *priv = CE_PAGE_8021X_SECURITY_GET_PRIVATE (object);
 
-       if (priv->disposed)
-               return;
-
-       priv->disposed = TRUE;
-
-       if (priv->security)
+       if (priv->security) {
                wireless_security_unref (priv->security);
+               priv->security = NULL;
+       }
 
        G_OBJECT_CLASS (ce_page_8021x_security_parent_class)->dispose (object);
 }
diff --git a/src/connection-editor/page-dsl.c b/src/connection-editor/page-dsl.c
index ea35b27..c327979 100644
--- a/src/connection-editor/page-dsl.c
+++ b/src/connection-editor/page-dsl.c
@@ -45,8 +45,6 @@ typedef struct {
        GtkEntry *username;
        GtkEntry *password;
        GtkEntry *service;
-
-       gboolean disposed;
 } CEPageDslPrivate;
 
 static void
diff --git a/src/connection-editor/page-ethernet.c b/src/connection-editor/page-ethernet.c
index d24a10f..16c8204 100644
--- a/src/connection-editor/page-ethernet.c
+++ b/src/connection-editor/page-ethernet.c
@@ -49,8 +49,6 @@ typedef struct {
        GtkToggleButton *duplex;
        GtkToggleButton *autonegotiate;
        GtkSpinButton *mtu;
-
-       gboolean disposed;
 } CEPageEthernetPrivate;
 
 #define PORT_DEFAULT  0
diff --git a/src/connection-editor/page-general.c b/src/connection-editor/page-general.c
index 462e546..5cece09 100644
--- a/src/connection-editor/page-general.c
+++ b/src/connection-editor/page-general.c
@@ -151,16 +151,10 @@ general_private_init (CEPageGeneral *self)
 static void
 dispose (GObject *object)
 {
-       CEPageGeneral *self = CE_PAGE_GENERAL (object);
-       CEPageGeneralPrivate *priv = CE_PAGE_GENERAL_GET_PRIVATE (self);
-
-       if (priv->remote_settings) {
-               g_object_unref (priv->remote_settings);
-               priv->remote_settings = NULL;
-       }
+       CEPageGeneralPrivate *priv = CE_PAGE_GENERAL_GET_PRIVATE (object);
 
-       g_strfreev (priv->zones);
-       priv->zones = NULL;
+       g_clear_object (&priv->remote_settings);
+       g_clear_pointer (&priv->zones, g_strfreev);
 
        G_OBJECT_CLASS (ce_page_general_parent_class)->dispose (object);
 }
diff --git a/src/connection-editor/page-ip4.c b/src/connection-editor/page-ip4.c
index fe1a575..f47725a 100644
--- a/src/connection-editor/page-ip4.c
+++ b/src/connection-editor/page-ip4.c
@@ -1245,14 +1245,13 @@ dispose (GObject *object)
        CEPageIP4Private *priv = CE_PAGE_IP4_GET_PRIVATE (self);
        int i;
 
-       if (priv->window_group)
-               g_object_unref (priv->window_group);
+       g_clear_object (&priv->window_group);
 
        /* Mark CEPageIP4 object as invalid; store this indication to cells to be usable in callbacks */
        for (i = 0; i <= COL_LAST; i++)
                g_object_set_data (G_OBJECT (priv->addr_cells[i]), "ce-page-not-valid", GUINT_TO_POINTER (1));
 
-       g_free (priv->connection_id);
+       g_clear_pointer (&priv->connection_id, g_free);
 
        G_OBJECT_CLASS (ce_page_ip4_parent_class)->dispose (object);
 }
diff --git a/src/connection-editor/page-ip6.c b/src/connection-editor/page-ip6.c
index 5796441..5340d78 100644
--- a/src/connection-editor/page-ip6.c
+++ b/src/connection-editor/page-ip6.c
@@ -1232,14 +1232,13 @@ dispose (GObject *object)
        CEPageIP6Private *priv = CE_PAGE_IP6_GET_PRIVATE (self);
        int i;
 
-       if (priv->window_group)
-               g_object_unref (priv->window_group);
+       g_clear_object (&priv->window_group);
 
        /* Mark CEPageIP6 object as invalid; store this indication to cells to be usable in callbacks */
        for (i = 0; i <= COL_LAST; i++)
                g_object_set_data (G_OBJECT (priv->addr_cells[i]), "ce-page-not-valid", GUINT_TO_POINTER (1));
 
-       g_free (priv->connection_id);
+       g_clear_pointer (&priv->connection_id, g_free);
 
        G_OBJECT_CLASS (ce_page_ip6_parent_class)->dispose (object);
 }
diff --git a/src/connection-editor/page-mobile.c b/src/connection-editor/page-mobile.c
index 5742426..b442a67 100644
--- a/src/connection-editor/page-mobile.c
+++ b/src/connection-editor/page-mobile.c
@@ -59,8 +59,6 @@ typedef struct {
 
        GtkWindowGroup *window_group;
        gboolean window_added;
-
-       gboolean disposed;
 } CEPageMobilePrivate;
 
 #define NET_TYPE_ANY         0
@@ -473,11 +471,7 @@ validate (CEPage *page, NMConnection *connection, GError **error)
 static void
 dispose (GObject *object)
 {
-       CEPageMobile *self = CE_PAGE_MOBILE (object);
-       CEPageMobilePrivate *priv = CE_PAGE_MOBILE_GET_PRIVATE (self);
-
-       if (priv->window_group)
-               g_object_unref (priv->window_group);
+       g_clear_object (&CE_PAGE_MOBILE_GET_PRIVATE (object)->window_group);
 
        G_OBJECT_CLASS (ce_page_mobile_parent_class)->dispose (object);
 }
diff --git a/src/connection-editor/page-ppp.c b/src/connection-editor/page-ppp.c
index 2f9f8d6..7e7c1aa 100644
--- a/src/connection-editor/page-ppp.c
+++ b/src/connection-editor/page-ppp.c
@@ -75,8 +75,6 @@ typedef struct {
        GtkWindowGroup *window_group;
        gboolean window_added;
        char *connection_id;
-
-       gboolean disposed;
 } CEPagePppPrivate;
 
 static void
@@ -378,13 +376,10 @@ ce_page_ppp_init (CEPagePpp *self)
 static void
 dispose (GObject *object)
 {
-       CEPagePpp *self = CE_PAGE_PPP (object);
-       CEPagePppPrivate *priv = CE_PAGE_PPP_GET_PRIVATE (self);
-
-       if (priv->window_group)
-               g_object_unref (priv->window_group);
+       CEPagePppPrivate *priv = CE_PAGE_PPP_GET_PRIVATE (object);
 
-       g_free (priv->connection_id);
+       g_clear_object (&priv->window_group);
+       g_clear_pointer (&priv->connection_id, g_free);
 
        G_OBJECT_CLASS (ce_page_ppp_parent_class)->dispose (object);
 }
diff --git a/src/connection-editor/page-vpn.c b/src/connection-editor/page-vpn.c
index 81592c8..957f35d 100644
--- a/src/connection-editor/page-vpn.c
+++ b/src/connection-editor/page-vpn.c
@@ -50,8 +50,6 @@ typedef struct {
 
        NMVpnPluginUiInterface *plugin;
        NMVpnPluginUiWidgetInterface *ui;
-
-       gboolean disposed;
 } CEPageVpnPrivate;
 
 static void
@@ -166,15 +164,8 @@ dispose (GObject *object)
 {
        CEPageVpnPrivate *priv = CE_PAGE_VPN_GET_PRIVATE (object);
 
-       if (priv->disposed)
-               return;
-
-       priv->disposed = TRUE;
-
-       if (priv->ui)
-               g_object_unref (priv->ui);
-
-       g_free (priv->service_type);
+       g_clear_object (&priv->ui);
+       g_clear_pointer (&priv->service_type, g_free);
 
        G_OBJECT_CLASS (ce_page_vpn_parent_class)->dispose (object);
 }
diff --git a/src/connection-editor/page-wifi-security.c b/src/connection-editor/page-wifi-security.c
index 488898c..ef65fe6 100644
--- a/src/connection-editor/page-wifi-security.c
+++ b/src/connection-editor/page-wifi-security.c
@@ -435,7 +435,6 @@ ce_page_wifi_security_new (NMConnection *connection,
 static void
 ce_page_wifi_security_init (CEPageWifiSecurity *self)
 {
-       self->disposed = FALSE;
 }
 
 static void
@@ -443,13 +442,7 @@ dispose (GObject *object)
 {
        CEPageWifiSecurity *self = CE_PAGE_WIFI_SECURITY (object);
 
-       if (self->disposed)
-               return;
-
-       self->disposed = TRUE;
-
-       if (self->group)
-               g_object_unref (self->group);
+       g_clear_object (&self->group);
 
        G_OBJECT_CLASS (ce_page_wifi_security_parent_class)->dispose (object);
 }
diff --git a/src/connection-editor/page-wifi-security.h b/src/connection-editor/page-wifi-security.h
index a0dd0ed..b8072ab 100644
--- a/src/connection-editor/page-wifi-security.h
+++ b/src/connection-editor/page-wifi-security.h
@@ -43,7 +43,6 @@
 typedef struct {
        CEPage parent;
 
-       gboolean disposed;
        GtkSizeGroup *group;
        GtkComboBox *security_combo;
        gboolean adhoc;
diff --git a/src/connection-editor/page-wifi.c b/src/connection-editor/page-wifi.c
index d0a5617..dbf4e20 100644
--- a/src/connection-editor/page-wifi.c
+++ b/src/connection-editor/page-wifi.c
@@ -56,7 +56,6 @@ typedef struct {
        GtkSizeGroup *group;
 
        int last_channel;
-       gboolean disposed;
 } CEPageWifiPrivate;
 
 static void
diff --git a/src/connection-editor/page-wimax.c b/src/connection-editor/page-wimax.c
index ef5cd61..3b786c2 100644
--- a/src/connection-editor/page-wimax.c
+++ b/src/connection-editor/page-wimax.c
@@ -39,8 +39,6 @@ typedef struct {
 
        GtkEntry *name;
        GtkComboBoxText *device_mac;  /* Permanent MAC of the device */
-
-       gboolean disposed;
 } CEPageWimaxPrivate;
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]