From 16a8b24aac99af11adc7045d875650dc26c6c8e4 Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Thu, 13 Jul 2023 11:19:32 +0900 Subject: [PATCH] Fix memory leak Change-Id: Ic301fd47c05e30e3780e17f0afa5b420a5327666 --- packaging/mobileap-agent.spec | 2 +- src/mobileap_softap.c | 19 ++++++++----------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/packaging/mobileap-agent.spec b/packaging/mobileap-agent.spec index 0cfcf96..b471a2d 100644 --- a/packaging/mobileap-agent.spec +++ b/packaging/mobileap-agent.spec @@ -1,6 +1,6 @@ Name: mobileap-agent Summary: Mobile AP daemon for setting tethering environments -Version: 1.1.0 +Version: 1.1.1 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/src/mobileap_softap.c b/src/mobileap_softap.c index b0a967b..7035aad 100755 --- a/src/mobileap_softap.c +++ b/src/mobileap_softap.c @@ -649,26 +649,24 @@ static gboolean __hostapd_monitor_cb(GIOChannel *source, GIOCondition condition, if (ptr == NULL) { ERR("g_malloc failed\n"); g_free(mac); - mac = NULL; return TRUE; } - ptr->mac_addr = mac; - ptr->tid = g_timeout_add(HOSTAPD_DHCP_MAX_INTERVAL, - __hostapd_connect_timer_cb, mac); - sta_timer_list = g_slist_append(sta_timer_list, ptr); - band_update_info_t *info = NULL; - info = (band_update_info_t *)g_malloc(sizeof(band_update_info_t)); + band_update_info_t * info = (band_update_info_t *)g_malloc(sizeof(band_update_info_t)); if (info == NULL) { ERR("g_malloc failed\n"); g_free(mac); - mac = NULL; + g_free(ptr); return TRUE; } + + ptr->mac_addr = mac; + ptr->tid = g_timeout_add(HOSTAPD_DHCP_MAX_INTERVAL, + __hostapd_connect_timer_cb, mac); + + sta_timer_list = g_slist_append(sta_timer_list, ptr); info->mac_addr = g_strdup(mac); info->band = (hostapd_monitor_fd[HOSTAPD_WIFI_BAND_2G] == *data_fd) ? HOSTAPD_WIFI_BAND_2G : HOSTAPD_WIFI_BAND_5G; - g_free(mac); - mac = NULL; _add_mac_band_info(info); } else if (!strncmp(pbuf, HOSTAPD_STA_DISCONN, HOSTAPD_STA_DISCONN_LEN)) { @@ -699,7 +697,6 @@ static gboolean __hostapd_monitor_cb(GIOChannel *source, GIOCondition condition, */ _destroy_dhcp_ack_timer(mac); g_free(mac); - mac = NULL; discon_event = TRUE; } else { -- 2.7.4