Resolve memory leak in HAL 43/224643/2
authorAmit Purwar <amit.purwar@samsung.com>
Wed, 12 Feb 2020 05:46:02 +0000 (11:16 +0530)
committeramit purwar <amit.purwar@samsung.com>
Wed, 12 Feb 2020 06:42:29 +0000 (06:42 +0000)
Resolve memory leak related to g_variant_iter_loop

Change-Id: I3cc22a404a3c12a52c1b12b342c515e9674ee465
Signed-off-by: Amit Purwar <amit.purwar@samsung.com>
bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c
bt-oal/bluez_hal/src/bt-hal-agent.c
bt-oal/bluez_hal/src/bt-hal-dbus-common-utils.c
bt-oal/bluez_hal/src/bt-hal-device-dbus-handler.c
bt-oal/bluez_hal/src/bt-hal-event-receiver.c
bt-oal/bluez_hal/src/bt-hal-gatt-client.c
bt-oal/bluez_hal/src/bt-hal-hdp-dbus-handler.c

index 1bed8e3..3f594c6 100644 (file)
@@ -744,6 +744,7 @@ static gboolean __bt_adapter_all_properties_cb(gpointer user_data)
        }
 done:
        g_variant_unref(result);
+       g_variant_iter_free(property_iter);
        return FALSE;
 }
 
index 09f395e..bc72fdf 100644 (file)
@@ -364,6 +364,8 @@ void __bt_hal_get_auth_info(GVariant *reply, char *auth_info)
                                g_variant_get(tmp_value, "ay", &value_iter);
                                while (g_variant_iter_loop(value_iter, "y", &m_value))
                                        manufacturer_data[i++] = m_value;
+
+                               g_variant_iter_free(value_iter);
                        }
                        g_variant_unref(tmp_value);
                } else {
index 71dee23..730fde4 100644 (file)
@@ -273,17 +273,23 @@ static char *__bt_hal_extract_control_device_path(GVariantIter *iter, char *addr
 {
        char *object_path = NULL;
        char *interface_str = NULL;
+       GVariantIter *interface_iter;
        char device_address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 };
 
        /* Parse the signature: oa{sa{sv}}} */
-       while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path, &interface_str)) {
+       while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path, &interface_iter)) {
                if (object_path == NULL)
-                       return  NULL;
+                       continue;
 
-               if (g_strcmp0(interface_str, BT_HAL_PLAYER_CONTROL_INTERFACE) == 0) {
-                       _bt_hal_convert_device_path_to_address(object_path, device_address);
-                       if (g_strcmp0(address, device_address) == 0)
-                               return g_strdup(object_path);
+               while(g_variant_iter_loop(interface_iter, "{&sa{sv}}", &interface_str, NULL)) {
+                       if (g_strcmp0(interface_str, BT_HAL_PLAYER_CONTROL_INTERFACE) == 0) {
+                               _bt_hal_convert_device_path_to_address(object_path, device_address);
+                               if (g_strcmp0(address, device_address) == 0) {
+                                       DBG("Object Path: %s", object_path);
+                                       g_variant_iter_free(interface_iter);
+                                       return g_strdup(object_path);
+                               }
+                       }
                }
        }
        return NULL;
@@ -293,17 +299,23 @@ static char *__bt_hal_extract_transport_device_path(GVariantIter *iter, char *ad
 {
        char *object_path = NULL;
        char *interface_str = NULL;
+       GVariantIter *interface_iter;
        char device_address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 };
 
        /* Parse the signature: oa{sa{sv}}} */
-       while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path, &interface_str)) {
+       while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path, &interface_iter)) {
                if (object_path == NULL)
-                       return  NULL;
+                       continue;
 
-               if (g_strcmp0(interface_str, BT_HAL_MEDIATRANSPORT_INTERFACE) == 0) {
-                       _bt_hal_convert_device_path_to_address(object_path, device_address);
-                       if (g_strcmp0(address, device_address) == 0)
-                               return g_strdup(object_path);
+               while(g_variant_iter_loop(interface_iter, "{&sa{sv}}", &interface_str, NULL)) {
+                       if (g_strcmp0(interface_str, BT_HAL_MEDIATRANSPORT_INTERFACE) == 0) {
+                               _bt_hal_convert_device_path_to_address(object_path, device_address);
+                               if (g_strcmp0(address, device_address) == 0) {
+                                       DBG("Object Path: %s", object_path);
+                                       g_variant_iter_free(interface_iter);
+                                       return g_strdup(object_path);
+                               }
+                       }
                }
        }
        return NULL;
@@ -1967,7 +1979,7 @@ gboolean _bt_hal_is_service_enabled(const char *uuid)
                return FALSE;
        }
 
-       while (g_variant_iter_loop(iter, "s", &uuid_str)) {
+       while (g_variant_iter_loop(iter, "&s", &uuid_str)) {
                DBG("UUID string [%s]\n", uuid_str);
                if (!strncasecmp(uuid, uuid_str, strlen(uuid))) {
                        ret = TRUE;
index 54f9339..bff47c4 100644 (file)
@@ -636,6 +636,7 @@ static void __bt_device_parse_services(GVariant *result)
        event_cb(HAL_EV_REMOTE_DEVICE_PROPS, (void*) buf, size);
 
        g_variant_unref(result);
+       g_variant_iter_free(property_iter);
 }
 
 int __bt_hal_dbus_enquire_remote_device_services(char *address)
@@ -937,6 +938,8 @@ static gboolean __bt_device_bonded_device_info_cb(gpointer user_data)
                        while (g_variant_iter_loop(char_value_iter, "y", &char_value))
                                g_byte_array_append(manufacturer_data, &char_value, 1);
 
+                       g_variant_iter_free(char_value_iter);
+
                        if (manufacturer_data) {
                                if (manufacturer_data->len > 0) {
                                        size += __bt_insert_hal_properties(
@@ -981,6 +984,7 @@ static gboolean __bt_device_bonded_device_info_cb(gpointer user_data)
 
 done:
        g_variant_unref(result);
+       g_variant_iter_free(property_iter);
        return FALSE;
 }
 
index 9321872..0ad6b41 100644 (file)
@@ -445,7 +445,7 @@ static void __bt_hal_adapter_property_changed_event(GVariant *msg)
                        ev->num_props++;
                } else if (!g_strcmp0(key, "Modalias")) {
                        char *modalias = NULL;
-                       g_variant_get(value, "s", &modalias);
+                       g_variant_get(value, "&s", &modalias);
                        DBG("##Adapter ModAlias [%s]", modalias);
                } else if (!g_strcmp0(key, "SupportedLEFeatures")) {
                        DBG("##LE Supported features");
@@ -2499,9 +2499,6 @@ static void __bt_hal_handle_avrcp_ctrl_events(GVariant *msg, const char *member,
                        DBG("Property not handled");
                }
        }
-
-       g_free((char *)property);
-       g_variant_unref(value);
 }
 
 static void __bt_hal_handle_avrcp_transport_events(GVariant *msg, const char *member,
@@ -2546,9 +2543,6 @@ static void __bt_hal_handle_avrcp_transport_events(GVariant *msg, const char *me
                        DBG("Property not handled");
                }
        }
-
-       g_free((char *)property);
-       g_variant_unref(value);
 }
 
 /* A2DP Src Role(Remote:Sink) Events */
index 0789abe..6d6ef88 100644 (file)
@@ -1121,11 +1121,13 @@ static bt_status_t _hal_gattc_get_characteristic_info(hal_gattc_char_t *gattc_ch
                                char_permission |= _hal_get_permission_flag(permission);
                        }
                        __hal_convert_permission_flag_to_str(char_permission);
+                       g_variant_iter_free(char_perm_iter);
                } else if (!g_strcmp0(key, "Descriptors")) {
                        g_variant_get(value, "ao", &char_desc_iter);
                        while (g_variant_iter_loop(char_desc_iter, "&o", &char_desc_handle)) {
                                g_ptr_array_add(gp_desc_array, (gpointer)char_desc_handle);
                        }
+                       g_variant_iter_free(char_desc_iter);
                }
        }
 
@@ -1266,6 +1268,9 @@ static bt_status_t _hal_gattc_get_descriptor_info(hal_gattc_desc_t *gattc_desc)
                if (!g_strcmp0(key, "UUID")) {
                        desc_uuid_str = g_variant_get_string(value, &len);
                        _hal_gattc_update_desc_property(gattc_desc, desc_uuid_str);
+
+                       g_free((gchar *)key);
+                       g_variant_unref(value);
                        break;
                }
        }
@@ -3882,6 +3887,7 @@ static bt_status_t __hal_gattc_get_service_info(hal_gattc_server_info_t *server_
                                        DBG("char_handle: %s", char_handle);
                                        g_ptr_array_add(gp_char_array, (gpointer)char_handle);
                                }
+                               g_variant_iter_free(char_iter);
                        }
                }
        }
index 9bf3321..4061a42 100644 (file)
@@ -479,13 +479,14 @@ static void __hdp_handle_property_changed(GVariant *parameters)
                        INFO("Property MainChannel received");
                        obj_main_channel_path = g_variant_dup_string(value, &len);
                        DBG("Main Channel  Path = %s", obj_main_channel_path);
+
+                       g_free(property);
+                       g_variant_unref(value);
+                       g_free(obj_main_channel_path);
                        break;
                }
        }
        g_variant_iter_free(property_iter);
-       g_free(property);
-       g_variant_unref(value);
-       g_free(obj_main_channel_path);
 
        DBG("-");
 }