wifi-manager: Clear gdbus connection after it is unref'd 68/179068/1 submit/tizen/20180516.084045 submit/tizen/20180517.074802
authorSaurav Babu <saurav.babu@samsung.com>
Tue, 15 May 2018 11:38:32 +0000 (17:08 +0530)
committerSaurav Babu <saurav.babu@samsung.com>
Tue, 15 May 2018 11:38:32 +0000 (17:08 +0530)
In the below scenario:
 1. Initalize wifi manager
 2. Start WiFi Scan (or any other asynchronous method)
 3. Deinitialize wifi manager before asynchronous method is finished

At the time of deinitialization pending calls exist and gdbus connection
is unref'd but it is not cleared to NULL, so in future initializations
gdbus connection handle is corrupted and wifi_manager_initialize() is
failed.

https://developer.gnome.org/gobject/stable/gobject-The-Base-Object-Type.html#g-object-unref
states that if pointer to the GObject may be reused in future after
calling g_object_unref() then it is recommended to clear the pointer to
NULL rather than retain a dangling pointer to a potentially invalid
GObject instance using g_clear_object()

Change-Id: I36aa1184afed01c1dbc0779722239f262fb890f4
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
src/network_internal.c

index 89f4b95..eb4400c 100755 (executable)
@@ -570,7 +570,8 @@ void _net_dbus_pending_call_unref(void)
        if (gdbus_conn.conn_ref_count < 1)
                return;
 
-       g_object_unref(gdbus_conn.connection);
+       if (gdbus_conn.connection)
+               g_object_unref(gdbus_conn.connection);
 
        if (__sync_sub_and_fetch(&gdbus_conn.conn_ref_count, 1) < 1 &&
                        gdbus_conn.handle_libnetwork != NULL) {
@@ -625,9 +626,6 @@ int _net_dbus_close_gdbus_call(void)
 
        if (gdbus_conn.conn_ref_count < 1) {
                WIFI_LOG(WIFI_INFO, "There is no pending call");
-
-               g_object_unref(gdbus_conn.connection);
-               gdbus_conn.connection = NULL;
        } else {
                WIFI_LOG(WIFI_ERROR,
                                "There are %d pending calls, waiting to be cleared",
@@ -637,10 +635,11 @@ int _net_dbus_close_gdbus_call(void)
                        WIFI_LOG(WIFI_ERROR, "A handle of libnetwork is not NULL");
 
                gdbus_conn.handle_libnetwork = dlopen("/usr/lib/libnetwork.so", RTLD_LAZY);
-
-               g_object_unref(gdbus_conn.connection);
        }
 
+       g_object_unref(gdbus_conn.connection);
+       g_clear_object(&gdbus_conn.connection);
+
        return NET_ERR_NONE;
 }