From e6736b69f8676478ef2f1da08029991fb19b0a70 Mon Sep 17 00:00:00 2001 From: "injun.yang" Date: Fri, 29 May 2020 13:19:23 +0900 Subject: [PATCH] Fix the memory leak [Model] All [BinType] AP [Customer] OPEN [Issue#] P200528-00621 [Request] Internal [Occurrence Version] N/A [Problem] memory leak [Cause & Measure] leak [Checking Method] basic test [Team] Convergence BT [Developer] Injun Yang [Solution company] Samsung [Change Type] Specification change Change-Id: I04a8bb10165a908042e66d86fc2307ac614f0cc7 Signed-off-by: injun.yang Signed-off-by: Wootak Jung --- bt-oal/bluez_hal/src/bt-hal-agent.c | 30 ++++++++++++++++++---------- bt-oal/bluez_hal/src/bt-hal-event-receiver.c | 24 ++++++++++------------ 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/bt-oal/bluez_hal/src/bt-hal-agent.c b/bt-oal/bluez_hal/src/bt-hal-agent.c index 0bccf14..b0d7e9c 100644 --- a/bt-oal/bluez_hal/src/bt-hal-agent.c +++ b/bt-oal/bluez_hal/src/bt-hal-agent.c @@ -395,9 +395,9 @@ void __bt_hal_get_auth_info(GVariant *reply, char *auth_info) static gboolean __bt_hal_pincode_request(GapAgentPrivate *agent, GDBusProxy *device) { uint32_t device_class; - const gchar *address; + gchar *address; unsigned char auth_info[5] = {0, }; - const gchar *name; + gchar *name; GVariant *reply = NULL; GVariant *reply_temp = NULL; GVariant *tmp_value; @@ -466,6 +466,8 @@ static gboolean __bt_hal_pincode_request(GapAgentPrivate *agent, GDBusProxy *dev } done: + g_free(name); + g_free(address); g_variant_unref(reply); g_variant_unref(reply_temp); __bt_hal_agent_release_memory(); @@ -516,8 +518,8 @@ static void __bt_hal_send_ssp_request_events(const gchar *address, static gboolean __bt_hal_display_request(GapAgentPrivate *agent, GDBusProxy *device, guint passkey) { - const gchar *address; - const gchar *name; + gchar *address; + gchar *name; unsigned char auth_info[5] = {0, }; char *str_passkey; uint32_t device_class; @@ -576,6 +578,8 @@ static gboolean __bt_hal_display_request(GapAgentPrivate *agent, GDBusProxy *dev g_free(str_passkey); done: + g_free(name); + g_free(address); g_variant_unref(reply); g_variant_unref(reply_temp); __bt_hal_agent_release_memory(); @@ -587,8 +591,8 @@ done: /* SSP */ static gboolean __bt_hal_passkey_request(GapAgentPrivate *agent, GDBusProxy *device) { - const gchar *address; - const gchar *name; + gchar *address; + gchar *name; unsigned char auth_info[5] = {0, }; uint32_t device_class; GVariant *reply = NULL; @@ -638,6 +642,8 @@ static gboolean __bt_hal_passkey_request(GapAgentPrivate *agent, GDBusProxy *dev } done: + g_free(name); + g_free(address); g_variant_unref(reply); g_variant_unref(reply_temp); __bt_hal_agent_release_memory(); @@ -650,8 +656,8 @@ done: static gboolean __bt_hal_confirm_request(GapAgentPrivate *agent, GDBusProxy *device, guint passkey) { - const gchar *address; - const gchar *name; + gchar *address; + gchar *name; char str_passkey[7]; uint32_t device_class; GVariant *reply_temp = NULL; @@ -711,6 +717,8 @@ static gboolean __bt_hal_confirm_request(GapAgentPrivate *agent, GDBusProxy *dev } done: + g_free(name); + g_free(address); g_variant_unref(reply); g_variant_unref(reply_temp); __bt_hal_agent_release_memory(); @@ -721,8 +729,8 @@ done: static gboolean __bt_hal_authorize_request(GapAgentPrivate *agent, GDBusProxy *device, const char *uuid) { - const gchar *address; - const gchar *name; + gchar *address; + gchar *name; gboolean trust; gboolean paired; GVariant *reply = NULL; @@ -859,6 +867,8 @@ static gboolean __bt_hal_authorize_request(GapAgentPrivate *agent, GDBusProxy *d } done: + g_free(name); + g_free(address); g_variant_unref(reply); g_variant_unref(reply_temp); __bt_hal_agent_release_memory(); diff --git a/bt-oal/bluez_hal/src/bt-hal-event-receiver.c b/bt-oal/bluez_hal/src/bt-hal-event-receiver.c index a6ff12f..bc9386e 100644 --- a/bt-oal/bluez_hal/src/bt-hal-event-receiver.c +++ b/bt-oal/bluez_hal/src/bt-hal-event-receiver.c @@ -1041,7 +1041,7 @@ static gboolean __bt_hal_event_manager(gpointer data) if (obj_path == NULL) { ERR("obj_path is NULL"); - return FALSE; + goto done; } if (strcasecmp(obj_path, BT_HAL_BLUEZ_HCI_PATH) == 0) { @@ -1078,20 +1078,20 @@ static gboolean __bt_hal_event_manager(gpointer data) if (g_strcmp0(g_variant_get_type_string(param->parameters), "(sss)") != 0) { ERR("Invalid variant format"); - return FALSE; + goto done; } /* TODO: Handle Name Owener changed Signal */ if (__bt_hal_get_owner_info(param->parameters, &name, &previous, ¤t)) { ERR("Fail to get the owner info"); - return FALSE; + goto done; } if (*current != '\0') - return FALSE; + goto done; if (name == NULL) - return FALSE; + goto done; if (strcasecmp(name, BT_HAL_BLUEZ_NAME) == 0) { struct hal_ev_adapter_state_changed ev; @@ -1148,12 +1148,14 @@ static gboolean __bt_hal_event_manager(gpointer data) __bt_hal_handle_gatt_service_event(param->parameters, param->signal_name); } +done: /* Free data */ g_free(param->sender_name); g_free(param->object_path); g_free(param->interface_name); g_free(param->signal_name); g_variant_unref(param->parameters); + g_free(param); return FALSE; } @@ -1198,10 +1200,6 @@ static void __bt_hal_handle_headset_events(GVariant *msg, const char *member, co address = g_malloc0(BT_HAL_ADDRESS_STRING_SIZE); - /* Fix : NULL_RETURNS */ - if (address == NULL) - return; - _bt_hal_convert_device_path_to_address(path, address); __bt_hal_send_hf_audio_connection_state_event(property_flag, address); g_free(address); @@ -1222,8 +1220,6 @@ static void __bt_hal_handle_headset_events(GVariant *msg, const char *member, co DBG("Sco Disconnected"); } else { ERR("Not handled state - %s", state); - g_free(state); - return; } g_free(state); } else if (strcasecmp(property, "SpeakerGain") == 0) { @@ -1248,8 +1244,7 @@ static void __bt_hal_handle_headset_events(GVariant *msg, const char *member, co g_free(address); } - if (property) - g_free(property); + g_free(property); g_variant_unref(value); } @@ -1964,11 +1959,11 @@ static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *me const char *path) { char *address; - const char *property = NULL; if (path == NULL) return; if (strcasecmp(member, "PropertyChanged") == 0) { + char *property; g_variant_get(msg, "(s)", &property); if (property == NULL) return; @@ -2008,6 +2003,7 @@ static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *me } else if (strcasecmp(property, "UUIDs") == 0) { /* TODO */ } + g_free(property); } else if (strcasecmp(member, "DeviceConnected") == 0) { unsigned char addr_type = 0; -- 2.7.4