Fix memory leak 36/153436/1 accepted/tizen/4.0/unified/20170929.080706 submit/tizen_4.0/20170929.021712 tizen_4.0.IoT.p1_release
authorSeungyoun Ju <sy39.ju@samsung.com>
Fri, 22 Sep 2017 02:07:31 +0000 (11:07 +0900)
committerSeungyoun Ju <sy39.ju@samsung.com>
Thu, 28 Sep 2017 10:23:37 +0000 (19:23 +0900)
[Problem] There are some memory leak in code
[Cause & Measure] Fix memory leak

324 bytes in 18 blocks are definitely lost in loss record 1,471 of 1,512
at 0x48458E8: malloc (vg_replace_malloc.c:299)
by 0x4B9E271: g_variant_get (gvariant.c:5368)
by 0x12DAC5: _bt_get_remote_device_info_by_object_path (bt-service-device.c:516)
by 0x11A295: __bt_device_property_changed_event (bt-service-event-receiver.c:1076)
by 0x11A295: _bt_handle_property_changed_event (bt-service-event-receiver.c:1403)
by 0x11D235: __bt_manager_event_filter (bt-service-event-receiver.c:2885)

504 bytes in 72 blocks are definitely lost in loss record 1,479 of 1,512
at 0x48458E8: malloc (vg_replace_malloc.c:299)
by 0x4B9E271: g_variant_get (gvariant.c:5368)
by 0x12579D: __bt_get_bonded_device_info (bt-service-adapter.c:374)
by 0x12579D: _bt_get_bonded_device_info (bt-service-adapter.c:3153)
by 0x143815: __bt_bluez_request (bt-request-handler.c:880)
by 0x147439: __bt_service_method (bt-request-handler.c:275)

648 bytes in 36 blocks are definitely lost in loss record 1,486 of 1,512
at 0x48458E8: malloc (vg_replace_malloc.c:299)
by 0x4B9E271: g_variant_get (gvariant.c:5368)
by 0x13402F: _bt_get_device_ida (bt-service-device.c:3563)
by 0x1449ED: __bt_bluez_request (bt-request-handler.c:1792)
by 0x147439: __bt_service_method (bt-request-handler.c:275)

1,008 bytes in 36 blocks are definitely lost in loss record 1,490 of 1,512
at 0x48458E8: malloc (vg_replace_malloc.c:299)
by 0x4B79E89: g_malloc (gmem.c:97)
by 0x4B89755: g_slice_alloc (gslice.c:1007)
by 0x4B5664B: g_array_sized_new (garray.c:193)
by 0x147191: __bt_service_method (bt-request-handler.c:220)

21,852 bytes in 1,214 blocks are definitely lost in loss record 1,509 of 1,512
at 0x48458E8: malloc (vg_replace_malloc.c:299)
by 0x4B9E271: g_variant_get (gvariant.c:5368)
by 0x11B96D: _bt_handle_device_event (bt-service-event-receiver.c:2200)
by 0x11D8B1: __bt_manager_event_filter (bt-service-event-receiver.c:2897)

22,662 (432 direct, 22,230 indirect) bytes in 18 blocks are definitely lost in loss record 1,511 of 1,512
at 0x48458E8: malloc (vg_replace_malloc.c:299)
by 0x4B9E271: g_variant_get (gvariant.c:5368)
by 0x11D17D: __bt_manager_event_filter (bt-service-event-receiver.c:2679)

Change-Id: Ib00c46ac04eff5d62b94bbf31876bd06dac6aa2a
Signed-off-by: Seungyoun Ju <sy39.ju@samsung.com>
bt-service/bt-request-handler.c
bt-service/bt-service-adapter.c
bt-service/bt-service-audio.c
bt-service/bt-service-device.c
bt-service/bt-service-event-receiver.c

index a6fb1e4..a9567ed 100644 (file)
@@ -263,19 +263,16 @@ static void __bt_service_method(GDBusConnection *connection,
 
                                GVariant *temp = g_variant_new("(iv)", result, out_var);
                                g_dbus_method_invocation_return_value(invocation, temp);
-
-                               g_array_free(out_param1, TRUE);
-                               out_param1 = NULL;
                        }
                }
                /* TODO: MAP? see the if{}else{} above */
 
+               g_array_free(out_param1, TRUE);
                g_variant_unref(param1);
                g_variant_unref(param2);
                g_variant_unref(param3);
                g_variant_unref(param4);
                g_variant_unref(param5);
-//             g_free(sender);
                FN_END;
                return;
 fail:
@@ -300,7 +297,6 @@ fail:
                g_variant_unref(param3);
                g_variant_unref(param4);
                g_variant_unref(param5);
-//             g_free(sender);
        }
 
        FN_END;
index 5d00193..d06b753 100644 (file)
@@ -292,6 +292,7 @@ static int __bt_get_bonded_device_info(gchar *device_path,
        GDBusProxy *device_proxy;
        gchar *address = NULL;
        gchar *name = NULL;
+       gchar *alias = NULL;
        unsigned int cod = 0;
        gint rssi = 0;
        gboolean trust = FALSE;
@@ -350,10 +351,9 @@ static int __bt_get_bonded_device_info(gchar *device_path,
                } else if (!g_strcmp0(key, "Address")) {
                        g_variant_get(value, "s", &address);
                } else if (!g_strcmp0(key, "Alias")) {
-                       g_variant_get(value, "s", &name);
+                       g_variant_get(value, "s", &alias);
                } else if (!g_strcmp0(key, "Name")) {
-                       if (!name)
-                               g_variant_get(value, "s", &name);
+                       g_variant_get(value, "s", &name);
                } else if (!g_strcmp0(key, "Class")) {
                        cod = g_variant_get_uint32(value);
                } else if (!g_strcmp0(key, "Connected")) {
@@ -391,6 +391,7 @@ static int __bt_get_bonded_device_info(gchar *device_path,
 
        if ((paired == FALSE) && (trust == FALSE)) {
                g_free(address);
+               g_free(alias);
                g_free(name);
                return BLUETOOTH_ERROR_NOT_PAIRED;
        }
@@ -400,7 +401,7 @@ static int __bt_get_bonded_device_info(gchar *device_path,
 
        _bt_divide_device_class(&dev_info->device_class, cod);
 
-       g_strlcpy(dev_info->device_name.name, name,
+       g_strlcpy(dev_info->device_name.name, alias ? alias : name,
                        BLUETOOTH_DEVICE_NAME_LENGTH_MAX+1);
 
        dev_info->rssi = rssi;
@@ -409,6 +410,7 @@ static int __bt_get_bonded_device_info(gchar *device_path,
        dev_info->connected = connected;
        ret = BLUETOOTH_ERROR_NONE;
        g_free(address);
+       g_free(alias);
        g_free(name);
 
        return ret;
index e611731..2200aa9 100644 (file)
@@ -847,9 +847,6 @@ int _bt_audio_connect(int request_id, int type,
                goto fail;
        }
 
-       if (out_param1)
-               g_array_free(out_param1, TRUE);
-
        return BLUETOOTH_ERROR_NONE;
 fail:
        if (out_param1 != NULL)
@@ -958,9 +955,6 @@ int _bt_audio_disconnect(int request_id, int type,
        }
        _bt_add_headset_to_list(type, BT_STATE_DISCONNECTING, address);
 
-       if (out_param1)
-               g_array_free(out_param1, TRUE);
-
        return BLUETOOTH_ERROR_NONE;
 fail:
        if (out_param1 != NULL)
@@ -1105,8 +1099,6 @@ int _bt_hf_disconnect(int request_id,
                return ret;
        }
        g_free(uuid);
-       if (out_param1)
-               g_array_free(out_param1, TRUE);
 
        return BLUETOOTH_ERROR_NONE;
 fail:
index 32297fc..35a8428 100644 (file)
@@ -457,9 +457,8 @@ bt_remote_dev_info_t *_bt_get_remote_device_info_by_object_path(
                g_variant_get(tmp_value, "s", &address);
                g_variant_unref(tmp_value);
 
-               dev_info->address = g_strdup(address);
-               dev_info->name = g_strdup(name);
-               g_free(name);
+               dev_info->address = address;
+               dev_info->name = name;
                g_variant_unref(value);
        } else {
                BT_ERR("result  is NULL\n");
@@ -3331,47 +3330,36 @@ int _bt_get_device_ida(bluetooth_device_address_t *device_address,
        retv_if(device_path == NULL, BLUETOOTH_ERROR_NOT_PAIRED);
 
        device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
-                                                               NULL, BT_BLUEZ_NAME,
-                                                               device_path, BT_DEVICE_INTERFACE,  NULL, NULL);
+                       NULL, BT_BLUEZ_NAME,
+                       device_path, BT_DEVICE_INTERFACE,  NULL, NULL);
        g_free(device_path);
        if (!device_proxy) {
                BT_ERR("Unable to get proxy");
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       result = g_dbus_proxy_call_sync(device_proxy, "GetIDAddress",
-                                NULL,
-                                G_DBUS_CALL_FLAGS_NONE,
-                                -1,
-                                NULL,
-                                &error);
-
+       result = g_dbus_proxy_call_sync(device_proxy, "GetIDAddress", NULL,
+                       G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
        if (result == NULL) {
                BT_ERR("Failed to get device ID address");
                if (error != NULL) {
-                       BT_ERR("Error occured in Proxy call [%s]\n", error->message);
+                       BT_ERR("Error occured in Proxy call [%s]", error->message);
                        g_error_free(error);
                }
                g_object_unref(device_proxy);
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       g_variant_get(result , "(s)", &idaddress);
-       g_variant_unref(result);
-
+       g_variant_get(result , "(&s)", &idaddress);
        if (idaddress == NULL) {
                BT_ERR("No paired device");
-               g_object_unref(device_proxy);
-               return BLUETOOTH_ERROR_NOT_PAIRED;
-       }
-
-       BT_DBG("ID Address:%s", idaddress);
-
-       if (idaddress)
+               ret = BLUETOOTH_ERROR_NOT_PAIRED;
+       } else {
+               DBG_SECURE("ID Address : %s", idaddress);
                _bt_convert_addr_string_to_type(id_address->addr, idaddress);
-       else
-               ret = BLUETOOTH_ERROR_INTERNAL;
+       }
 
+       g_variant_unref(result);
        g_object_unref(device_proxy);
 
        return ret;
index c38dbab..9b468bf 100644 (file)
@@ -2159,12 +2159,12 @@ void _bt_handle_device_event(GVariant *msg, const char *member, const char *path
 
                le_dev_info = g_malloc0(sizeof(bt_remote_le_dev_info_t));
 
-               g_variant_get(msg, "(syyii@ay)", &le_dev_info->address,
-                                               &le_dev_info->addr_type,
-                                               &le_dev_info->adv_type,
-                                               &le_dev_info->rssi,
-                                               &le_dev_info->adv_data_len,
-                                               &value);
+               g_variant_get(msg, "(&syyii@ay)", &le_dev_info->address,
+                                                 &le_dev_info->addr_type,
+                                                 &le_dev_info->adv_type,
+                                                 &le_dev_info->rssi,
+                                                 &le_dev_info->adv_data_len,
+                                                 &value);
 
                if (value == NULL) {
                        _bt_free_le_device_info(le_dev_info);
@@ -2781,8 +2781,11 @@ static  void __bt_manager_event_filter(GDBusConnection *connection,
 #ifdef TIZEN_FEATURE_BT_DPM
                                int desktop_state = DPM_BT_ERROR;
 #endif
-                               ret_if(_bt_is_discovering() == FALSE &&
-                                               _bt_is_le_scanning() == FALSE);
+                               if (_bt_is_discovering() == FALSE &&
+                                   _bt_is_le_scanning() == FALSE) {
+                                       g_variant_unref(value);
+                                       return;
+                               }
 
                                cache_info = g_malloc0(sizeof(bt_cache_info_t));