vpn-provider: Unregister provider from dbus when freed
authorJukka Rissanen <jukka.rissanen@linux.intel.com>
Fri, 30 Nov 2012 09:30:50 +0000 (11:30 +0200)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Fri, 30 Nov 2012 13:01:19 +0000 (15:01 +0200)
The provider object was not unregistered from dbus watch
when the provider was removed which caused free memory access
error.

vpn/vpn-provider.c

index 9bbb10f..0b164c0 100644 (file)
@@ -1436,12 +1436,48 @@ int vpn_provider_indicate_error(struct vpn_provider *provider,
        return 0;
 }
 
+static int connection_unregister(struct vpn_provider *provider)
+{
+       DBG("provider %p path %s", provider, provider->path);
+
+       if (provider->path == NULL)
+               return -EALREADY;
+
+       g_dbus_unregister_interface(connection, provider->path,
+                               VPN_CONNECTION_INTERFACE);
+
+       g_free(provider->path);
+       provider->path = NULL;
+
+       return 0;
+}
+
+static int connection_register(struct vpn_provider *provider)
+{
+       DBG("provider %p path %s", provider, provider->path);
+
+       if (provider->path != NULL)
+               return -EALREADY;
+
+       provider->path = g_strdup_printf("%s/connection/%s", VPN_PATH,
+                                               provider->identifier);
+
+       g_dbus_register_interface(connection, provider->path,
+                               VPN_CONNECTION_INTERFACE,
+                               connection_methods, connection_signals,
+                               NULL, provider, NULL);
+
+       return 0;
+}
+
 static void unregister_provider(gpointer data)
 {
        struct vpn_provider *provider = data;
 
        configuration_count_del();
 
+       connection_unregister(provider);
+
        vpn_provider_unref(provider);
 }
 
@@ -1518,38 +1554,6 @@ static void provider_dbus_ident(char *ident)
        }
 }
 
-static int connection_unregister(struct vpn_provider *provider)
-{
-       if (provider->path == NULL)
-               return -EALREADY;
-
-       g_dbus_unregister_interface(connection, provider->path,
-                               VPN_CONNECTION_INTERFACE);
-
-       g_free(provider->path);
-       provider->path = NULL;
-
-       return 0;
-}
-
-static int connection_register(struct vpn_provider *provider)
-{
-       DBG("provider %p path %s", provider, provider->path);
-
-       if (provider->path != NULL)
-               return -EALREADY;
-
-       provider->path = g_strdup_printf("%s/connection/%s", VPN_PATH,
-                                               provider->identifier);
-
-       g_dbus_register_interface(connection, provider->path,
-                               VPN_CONNECTION_INTERFACE,
-                               connection_methods, connection_signals,
-                               NULL, provider, NULL);
-
-       return 0;
-}
-
 static struct vpn_provider *provider_create_from_keyfile(GKeyFile *keyfile,
                const char *ident)
 {