[network-manager-pptp/jk/pptp-dispose-fix] core: clear objects in dispose() else we could crash later (rh #1051727)



commit bfcd9725873cc83ac6ebb2bf732fee0e45e75295
Author: Jiří Klimeš <jklimes redhat com>
Date:   Fri May 16 13:03:30 2014 +0200

    core: clear objects in dispose() else we could crash later (rh #1051727)
    
    Also use g_clear_object() on other places to simplify the code.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1051727

 src/nm-pptp-service.c |   38 +++++++++-----------------------------
 1 files changed, 9 insertions(+), 29 deletions(-)
---
diff --git a/src/nm-pptp-service.c b/src/nm-pptp-service.c
index bca3e28..4954c5f 100644
--- a/src/nm-pptp-service.c
+++ b/src/nm-pptp-service.c
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 - 2011 Red Hat, Inc.
+ * (C) Copyright 2008 - 2014 Red Hat, Inc.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -1121,12 +1121,8 @@ real_connect (NMVPNPlugin   *plugin,
                return FALSE;
 
        /* Start our pppd plugin helper service */
-       if (priv->service)
-               g_object_unref (priv->service);
-       if (priv->connection) {
-               g_object_unref (priv->connection);
-               priv->connection = NULL;
-       }
+       g_clear_object (&priv->service);
+       g_clear_object (&priv->connection);
 
        /* Start our helper D-Bus service that the pppd plugin sends state changes to */
        priv->service = nm_pptp_ppp_service_new (gwaddr, connection, error);
@@ -1204,15 +1200,8 @@ real_disconnect (NMVPNPlugin   *plugin,
                priv->pid = 0;
        }
 
-       if (priv->connection) {
-               g_object_unref (priv->connection);
-               priv->connection = NULL;
-       }
-
-       if (priv->service) {
-               g_object_unref (priv->service);
-               priv->service = NULL;
-       }
+       g_clear_object (&priv->connection);
+       g_clear_object (&priv->service);
 
        return TRUE;
 }
@@ -1232,14 +1221,8 @@ state_changed_cb (GObject *object, NMVPNServiceState state, gpointer user_data)
        case NM_VPN_SERVICE_STATE_STOPPING:
        case NM_VPN_SERVICE_STATE_STOPPED:
                remove_timeout_handler (NM_PPTP_PLUGIN (object));
-               if (priv->connection) {
-                       g_object_unref (priv->connection);
-                       priv->connection = NULL;
-               }
-               if (priv->service) {
-                       g_object_unref (priv->service);
-                       priv->service = NULL;
-               }
+               g_clear_object (&priv->connection);
+               g_clear_object (&priv->service);
                break;
        default:
                break;
@@ -1251,11 +1234,8 @@ dispose (GObject *object)
 {
        NMPptpPluginPrivate *priv = NM_PPTP_PLUGIN_GET_PRIVATE (object);
 
-       if (priv->connection)
-               g_object_unref (priv->connection);
-
-       if (priv->service)
-               g_object_unref (priv->service);
+       g_clear_object (&priv->connection);
+       g_clear_object (&priv->service);
 
        G_OBJECT_CLASS (nm_pptp_plugin_parent_class)->dispose (object);
 }


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