Fix memory leak 24/295724/2
authorSeonah Moon <seonah1.moon@samsung.com>
Thu, 13 Jul 2023 02:19:32 +0000 (11:19 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Thu, 13 Jul 2023 05:19:27 +0000 (14:19 +0900)
Change-Id: Ic301fd47c05e30e3780e17f0afa5b420a5327666

packaging/mobileap-agent.spec
src/mobileap_softap.c

index 0cfcf96..b471a2d 100644 (file)
@@ -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
index b0a967b..7035aad 100755 (executable)
@@ -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 {