Add GVariant unreference logic 17/229817/1
authorWootak Jung <wootak.jung@samsung.com>
Mon, 6 Apr 2020 00:17:12 +0000 (09:17 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Mon, 6 Apr 2020 00:17:33 +0000 (09:17 +0900)
Change-Id: I7c5ceeef0114915c4140ae13a2527f21fc27c672

bt-oal/bluez_hal/src/bt-hal-dbus-common-utils.c
bt-oal/bluez_hal/src/bt-hal-event-receiver.c
bt-oal/bluez_hal/src/bt-hal-hdp-dbus-handler.c
bt-oal/bluez_hal/src/bt-hal-rfcomm-dbus-handler.c
bt-service-adaptation/services/ipsp/bt-service-ipsp.c
bt-service-adaptation/services/obex/bt-service-map-client.c
bt-service/bt-service-adapter-le.c
bt-service/bt-service-device.c
bt-service/bt-service-proximity.c

index 10dde52..6d85936 100644 (file)
@@ -1275,6 +1275,7 @@ int _bt_hal_connect_profile(char *address, char *uuid,
        GDBusConnection *conn;
        GDBusProxy *adapter_proxy;
        GError *error = NULL;
+       GVariant *result;
 
        conn = _bt_hal_get_system_gconn();
        if (conn == NULL)
@@ -1288,16 +1289,19 @@ int _bt_hal_connect_profile(char *address, char *uuid,
                if (adapter_proxy == NULL)
                        return  BT_HAL_ERROR_INTERNAL;
 
-               g_dbus_proxy_call_sync(adapter_proxy, "CreateDevice",
+               result = g_dbus_proxy_call_sync(adapter_proxy, "CreateDevice",
                                g_variant_new("(s)", address),
                                G_DBUS_CALL_FLAGS_NONE,
                                -1,
                                NULL,
                                &error);
-
-               if (error != NULL) {
-                       ERR("CreateDevice Fail: %s", error->message);
-                       g_error_free(error);
+               if (!result) {
+                       if (error) {
+                               ERR("CreateDevice Fail: %s", error->message);
+                               g_error_free(error);
+                       }
+               } else {
+                       g_variant_unref(result);
                }
 
                object_path = _bt_hal_get_device_object_path(address);
@@ -1654,6 +1658,7 @@ int _bt_hal_cancel_discovers(char *address)
        GDBusProxy *adapter_proxy;
        GError *err = NULL;
        GDBusConnection *conn;
+       GVariant *ret = NULL;
 
        conn = _bt_hal_get_system_gconn();
        if (conn == NULL)
@@ -1661,7 +1666,6 @@ int _bt_hal_cancel_discovers(char *address)
 
        object_path = _bt_hal_get_device_object_path(address);
        if (object_path == NULL) {
-               GVariant *ret = NULL;
                INFO("No searched device");
                adapter_proxy = _bt_hal_get_adapter_proxy();
                if (adapter_proxy == NULL) {
@@ -1674,13 +1678,14 @@ int _bt_hal_cancel_discovers(char *address)
                                G_DBUS_CALL_FLAGS_NONE,
                                BT_HAL_MAX_DBUS_TIMEOUT, NULL,
                                &err);
-               if (err != NULL) {
-                       ERR("CreateDevice Failed: %s", err->message);
-                       g_clear_error(&err);
-               }
-
-               if (ret)
+               if (!ret) {
+                       if (err) {
+                               ERR("CreateDevice Failed: %s", err->message);
+                               g_clear_error(&err);
+                       }
+               } else {
                        g_variant_unref(ret);
+               }
 
                g_object_unref(adapter_proxy);
 
@@ -1694,15 +1699,19 @@ int _bt_hal_cancel_discovers(char *address)
                        BT_HAL_BLUEZ_NAME, object_path,
                        BT_HAL_DEVICE_INTERFACE,  NULL, NULL);
        g_free(object_path);
-       g_dbus_proxy_call_sync(proxy, "CancelDiscovery",
+       ret = g_dbus_proxy_call_sync(proxy, "CancelDiscovery",
                        NULL,
                        G_DBUS_CALL_FLAGS_NONE,
                        BT_HAL_MAX_DBUS_TIMEOUT, NULL,
                        &err);
-       if (err) {
-               ERR("DBus Error message: [%s]", err->message);
-               g_clear_error(&err);
-               return BT_STATUS_FAIL;
+       if (!ret) {
+               if (err) {
+                       ERR("DBus Error message: [%s]", err->message);
+                       g_clear_error(&err);
+                       return BT_STATUS_FAIL;
+               }
+       } else {
+               g_variant_unref(ret);
        }
 
        if (proxy)
index 7e5fe72..77ff0bb 100644 (file)
@@ -363,6 +363,7 @@ static void __bt_hal_adapter_property_changed_event(GVariant *msg)
                        DBG("##Discovering = [%d]", is_discovering);
 
                        if (is_discovering == FALSE) {
+                               GVariant *result;
                                /* In Tizen Bluez, this actually does not mean Discovery is stopped
                                   in Bluez. Tizen Bluez sends this event after a certain timeout,
                                   Therefore, we must forecefully call StopDiscovery to stop discovery in BlueZ */
@@ -376,33 +377,34 @@ static void __bt_hal_adapter_property_changed_event(GVariant *msg)
 
                                /* Need to stop searching */
                                DBG("Event though Bluez reported DIscovering stopped, we force stop Discovery ");
-                               g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
+                               result = g_dbus_proxy_call_sync(adapter_proxy, "StopDiscovery",
                                                NULL,
                                                G_DBUS_CALL_FLAGS_NONE,
                                                DBUS_TIMEOUT, NULL,
                                                &err);
-                               if (err) {
-                                       struct hal_ev_discovery_state_changed ev;
-
-                                       ERR("Dbus Error : %s", err->message);
-
-                                       if (g_strrstr(err->message, "No discovery started"))
+                               if (!result) {
+                                       if (err) {
+                                               struct hal_ev_discovery_state_changed ev;
+
+                                               ERR("Dbus Error : %s", err->message);
+
+                                               if (g_strrstr(err->message, "No discovery started"))
+                                                       continue;
+
+                                               /* This error is thrown by Bluez, as Discovery is already stopped.
+                                                  Discovery is stopped if user cancels on going discovery.
+                                                  In order to maintain correct state of Bluetooth Discovery state,
+                                                  simply send Discovery stopped event to HAL user */
+                                               ev.state = HAL_DISCOVERY_STATE_STOPPED;
+                                               event_cb(HAL_EV_DISCOVERY_STATE_CHANGED, &ev, sizeof(ev));
+                                               g_clear_error(&err);
                                                continue;
-
-                                       /* This error is thrown by Bluez, as Discovery is already stopped.
-                                          Discovery is stopped if user cancels on going discovery.
-                                          In order to maintain correct state of Bluetooth Discovery state,
-                                          simply send Discovery stopped event to HAL user */
-                                       ev.state = HAL_DISCOVERY_STATE_STOPPED;
-                                       event_cb(HAL_EV_DISCOVERY_STATE_CHANGED, &ev, sizeof(ev));
-                                       g_clear_error(&err);
-                                       continue;
-
+                                       }
                                } else {
+                                       g_variant_unref(result);
                                        event_id = g_timeout_add(BT_HAL_DISCOVERY_FINISHED_DELAY,
                                                        (GSourceFunc)__bt_hal_discovery_finished_cb, NULL);
                                }
-
                        } else {
                                struct hal_ev_discovery_state_changed ev;
                                ev.state = HAL_DISCOVERY_STATE_STARTED;
index 4061a42..7678685 100644 (file)
@@ -753,6 +753,8 @@ static void __hdp_disconnect_request_cb(GDBusProxy *hdp_proxy,
                /* Send channel_connect callback with status: connected */
                __hdp_send_conn_event(conn_info, BTHL_CONN_STATE_CONNECTED);
                return;
+       } else {
+               g_variant_unref(reply);
        }
 
        DBG("-");
index 81f75c6..c4cc17b 100644 (file)
@@ -419,6 +419,7 @@ static void __bt_connect_response_cb(GDBusProxy *proxy,
 {
        GError *error = NULL;
        rfcomm_cb_data_t *cb_data;
+       GVariant *result;
 
        DBG("+");
 
@@ -428,10 +429,13 @@ static void __bt_connect_response_cb(GDBusProxy *proxy,
                return;
        }
 
-       if (!g_dbus_proxy_call_finish(proxy, res, &error)) {
+       result = g_dbus_proxy_call_finish(proxy, res, &error);
+       if (!result) {
                ERR("Error : %s \n", error->message);
                __rfcomm_cb_data_remove(cb_data);
                g_error_free(error);
+       } else {
+               g_variant_unref(result);
        }
 
        if (proxy)
index 450ebec..e89ae05 100755 (executable)
@@ -39,6 +39,7 @@ int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
        GDBusProxy *adapter_proxy;
        GDBusConnection *conn;
        int ret = BLUETOOTH_ERROR_NONE;
+       GVariant *result;
 
        BT_CHECK_PARAMETER(bd_addr, return);
 
@@ -66,17 +67,21 @@ int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
        g_free(device_path);
        retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       g_dbus_proxy_call_sync(device_proxy, "ConnectIpsp",
+       result = g_dbus_proxy_call_sync(device_proxy, "ConnectIpsp",
                                NULL,
                                G_DBUS_CALL_FLAGS_NONE,
                                -1,
                                NULL,
                                &error);
-       if (error) {
-               BT_ERR("ConnectIpsp Call Error %s[%s]", error->message, device_address);
-               g_error_free(error);
-               g_object_unref(device_proxy);
-               return BLUETOOTH_ERROR_INTERNAL;
+       if (!result) {
+               if (error) {
+                       BT_ERR("ConnectIpsp Call Error %s[%s]", error->message, device_address);
+                       g_error_free(error);
+                       g_object_unref(device_proxy);
+                       return BLUETOOTH_ERROR_INTERNAL;
+               }
+       } else {
+               g_variant_unref(result);
        }
        g_object_unref(device_proxy);
 
@@ -102,6 +107,7 @@ int _bt_disconnect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
        GDBusProxy *adapter_proxy;
        GDBusConnection *conn;
        int ret = BLUETOOTH_ERROR_NONE;
+       GVariant *result;
 
        BT_CHECK_PARAMETER(bd_addr, return);
 
@@ -129,17 +135,21 @@ int _bt_disconnect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
        g_free(device_path);
        retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       g_dbus_proxy_call_sync(device_proxy, "DisconnectIpsp",
+       result = g_dbus_proxy_call_sync(device_proxy, "DisconnectIpsp",
                                NULL,
                                G_DBUS_CALL_FLAGS_NONE,
                                -1,
                                NULL,
                                &error);
-       if (error) {
-               BT_ERR("DisconnectIpsp Call Error %s[%s]", error->message, device_address);
-               g_error_free(error);
-               g_object_unref(device_proxy);
-               return BLUETOOTH_ERROR_INTERNAL;
+       if (!result) {
+               if (error) {
+                       BT_ERR("DisconnectIpsp Call Error %s[%s]", error->message, device_address);
+                       g_error_free(error);
+                       g_object_unref(device_proxy);
+                       return BLUETOOTH_ERROR_INTERNAL;
+               }
+       } else {
+               g_variant_unref(result);
        }
 
        g_object_unref(device_proxy);
index 15c0e85..326b2e8 100644 (file)
@@ -138,6 +138,7 @@ int _bt_destroy_session_sync(const char* session_id)
        GDBusConnection *g_conn;
        GDBusProxy *session_proxy;
        GError *err = NULL;
+       GVariant *result;
 
        retv_if(session_id == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
 
@@ -158,13 +159,16 @@ int _bt_destroy_session_sync(const char* session_id)
 
        GVariant *param = g_variant_new("(o)", session_id);
 
-       g_dbus_proxy_call_sync(session_proxy, "RemoveSession", param,
+       result = g_dbus_proxy_call_sync(session_proxy, "RemoveSession", param,
                        G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
-       if (err != NULL) {
-               BT_ERR("Could not remove session: %s\n", err->message);
-               g_error_free(err);
-               return BLUETOOTH_ERROR_INTERNAL;
+       if (!result) {
+               if (err) {
+                       BT_ERR("Could not remove session: %s\n", err->message);
+                       g_error_free(err);
+                       return BLUETOOTH_ERROR_INTERNAL;
+               }
        } else {
+               g_variant_unref(result);
                BT_DBG("remove session succeed\n");
        }
 
index b7d9c49..dee320f 100644 (file)
@@ -2310,6 +2310,7 @@ int _bt_le_set_data_length(bluetooth_device_address_t *device_address,
        gchar *device_path = NULL;
        GDBusConnection *conn;
        GDBusProxy *device_proxy;
+       GVariant *result;
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
 
@@ -2334,7 +2335,7 @@ int _bt_le_set_data_length(bluetooth_device_address_t *device_address,
        g_free(device_path);
        retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       g_dbus_proxy_call_sync(device_proxy,
+       result = g_dbus_proxy_call_sync(device_proxy,
                                        "LESetDataLength",
                                        g_variant_new("(qq)", txOctets, txTime),
                                        G_DBUS_CALL_FLAGS_NONE,
@@ -2350,6 +2351,9 @@ int _bt_le_set_data_length(bluetooth_device_address_t *device_address,
                 return BLUETOOTH_ERROR_INTERNAL;
        }
 
+       if (result)
+               g_variant_unref(result);
+
        return BLUETOOTH_ERROR_NONE;
 }
 
index 7a87ed7..83c358a 100644 (file)
@@ -678,14 +678,19 @@ static int __bt_cancel_bonding(void)
        /* First Cancel the ongoing pairing in bluez otherwise if we send
         * pair request bluez will send inprogress and we again retry bond so
         * this cycle continues */
-        GError *err = NULL;
-       g_dbus_proxy_call_sync(bonding_info->device_proxy, "CancelPairing",
+       GError *err = NULL;
+       GVariant *result;
+       result = g_dbus_proxy_call_sync(bonding_info->device_proxy, "CancelPairing",
                        NULL, G_DBUS_CALL_FLAGS_NONE,
                        10000, NULL, &err);
-       if (err) {
-               BT_ERR("Cancelling bonding request error msg (%s)", err->message);
-               g_clear_error(&err);
-               return BLUETOOTH_ERROR_PARING_FAILED;
+       if (!result) {
+               if (err) {
+                       BT_ERR("Cancelling bonding request error msg (%s)", err->message);
+                       g_clear_error(&err);
+                       return BLUETOOTH_ERROR_PARING_FAILED;
+               }
+       } else {
+               g_variant_unref(result);
        }
        return BLUETOOTH_ERROR_NONE;
 }
@@ -1997,6 +2002,7 @@ int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
        GDBusProxy *adapter_proxy;
        GDBusConnection *conn;
        int ret = BLUETOOTH_ERROR_NONE;
+       GVariant *result;
 
        BT_CHECK_PARAMETER(bd_addr, return);
 
@@ -2024,17 +2030,21 @@ int _bt_connect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
        g_free(device_path);
        retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       g_dbus_proxy_call_sync(device_proxy, "ConnectIpsp",
+       result = g_dbus_proxy_call_sync(device_proxy, "ConnectIpsp",
                                NULL,
                                G_DBUS_CALL_FLAGS_NONE,
                                -1,
                                NULL,
                                &error);
-       if (error) {
-               BT_ERR("ConnectIpsp Call Error %s[%s]", error->message, device_address);
-               g_error_free(error);
-               g_object_unref(device_proxy);
-               return BLUETOOTH_ERROR_INTERNAL;
+       if (!result) {
+               if (error) {
+                       BT_ERR("ConnectIpsp Call Error %s[%s]", error->message, device_address);
+                       g_error_free(error);
+                       g_object_unref(device_proxy);
+                       return BLUETOOTH_ERROR_INTERNAL;
+               }
+       } else {
+               g_variant_unref(result);
        }
 
        g_object_unref(device_proxy);
@@ -2051,6 +2061,7 @@ int _bt_disconnect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
        GDBusProxy *adapter_proxy;
        GDBusConnection *conn;
        int ret = BLUETOOTH_ERROR_NONE;
+       GVariant *result;
 
        BT_CHECK_PARAMETER(bd_addr, return);
 
@@ -2078,17 +2089,21 @@ int _bt_disconnect_le_ipsp_device(const bluetooth_device_address_t *bd_addr)
        g_free(device_path);
        retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       g_dbus_proxy_call_sync(device_proxy, "DisconnectIpsp",
+       result = g_dbus_proxy_call_sync(device_proxy, "DisconnectIpsp",
                                NULL,
                                G_DBUS_CALL_FLAGS_NONE,
                                -1,
                                NULL,
                                &error);
-       if (error) {
-               BT_ERR("DisconnectIpsp Call Error %s[%s]", error->message, device_address);
-               g_error_free(error);
-               g_object_unref(device_proxy);
-               return BLUETOOTH_ERROR_INTERNAL;
+       if (!result) {
+               if (error) {
+                       BT_ERR("DisconnectIpsp Call Error %s[%s]", error->message, device_address);
+                       g_error_free(error);
+                       g_object_unref(device_proxy);
+                       return BLUETOOTH_ERROR_INTERNAL;
+               }
+       } else {
+               g_variant_unref(result);
        }
 
        g_object_unref(device_proxy);
index 55a75e4..81e45e4 100644 (file)
@@ -331,6 +331,8 @@ int bt_register_proximity_reporter()
                }
                g_object_unref(proxy);
                return BLUETOOTH_ERROR_INTERNAL;
+       } else {
+               g_variant_unref(result);
        }
        g_object_unref(proxy);
 
@@ -374,6 +376,8 @@ int bt_unregister_proximity_reporter()
                }
                g_object_unref(proxy);
                return BLUETOOTH_ERROR_INTERNAL;
+       } else {
+               g_variant_unref(result);
        }
        g_object_unref(proxy);