From fce93b380eef966b7b683aede6aba73c72688740 Mon Sep 17 00:00:00 2001 From: Deokhyun Kim Date: Tue, 17 Sep 2019 10:43:35 +0900 Subject: [PATCH] Fix mem leak Change-Id: I3d25d486b5b9ee95fb1b3d3e0ba51f9ea004ea76 Signed-off-by: Deokhyun Kim --- bt-api/bt-common.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bt-api/bt-common.c b/bt-api/bt-common.c index e64a804..9d573f0 100644 --- a/bt-api/bt-common.c +++ b/bt-api/bt-common.c @@ -750,7 +750,6 @@ gboolean _bt_utf8_validate(char *name) return TRUE; } - static GDBusProxy *profile_gproxy; static int latest_id = -1; #define BT_RFCOMM_ID_MAX 245 @@ -1422,6 +1421,8 @@ int _bt_connect_profile(char *address, char *uuid, void *cb, DBUS_TIMEOUT, NULL, (GAsyncReadyCallback)cb, func_data); + if (cb == NULL) + g_object_unref(proxy); BT_DBG("-"); return BLUETOOTH_ERROR_NONE; } @@ -1467,6 +1468,8 @@ int _bt_discover_services(char *address, char *uuid, void *cb, DBUS_TIMEOUT, NULL, (GAsyncReadyCallback)cb, func_data); + if (cb == NULL) + g_object_unref(proxy); BT_DBG("-"); return BLUETOOTH_ERROR_NONE; } @@ -1687,6 +1690,8 @@ int _bt_disconnect_profile(char *address, char *uuid, void *cb, DBUS_TIMEOUT, NULL, (GAsyncReadyCallback)cb, func_data); + if (cb == NULL) + g_object_unref(proxy); BT_DBG("-"); return BLUETOOTH_ERROR_NONE; } @@ -1711,6 +1716,7 @@ int _bt_disconnect_ext_profile(char *address, char *path) g_variant_new("(o)", path), G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, NULL, NULL, NULL); + g_object_unref(proxy); BT_DBG("-"); return BLUETOOTH_ERROR_NONE; } @@ -2432,7 +2438,6 @@ BT_EXPORT_API int bluetooth_unregister_callback(void) { int ret; - ret = _bt_deinit_event_handler(); if (ret != BLUETOOTH_ERROR_NONE) BT_ERR("Fail to deinit the event handler"); @@ -2445,6 +2450,11 @@ BT_EXPORT_API int bluetooth_unregister_callback(void) _bt_gdbus_deinit_proxys(); + if (profile_gproxy) { + g_object_unref(profile_gproxy); + profile_gproxy = NULL; + } + if (system_private_conn) { g_object_unref(system_private_conn); system_private_conn = NULL; -- 2.7.4