Call get_backend and put_backend APIs only once 08/314608/1
authorJaehyun Kim <jeik01.kim@samsung.com>
Tue, 16 Jul 2024 06:49:20 +0000 (15:49 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Tue, 16 Jul 2024 06:49:20 +0000 (15:49 +0900)
Since hal_wifi_get_backend() is being called again
without calling hal_wifi_put_backend() after calling hal_wifi_get_backend(),
a memory leak is occurring internally.
Accordingly, net-config has been modified
to call the APIs only once at startup and termination.

Change-Id: Ib72b41b3c42eb91a1d02c26afec35a51a1e60179
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
src/main.c
src/wifi-firmware.c

index 3fe3d3b41de03455db95d6c5f7cd80072ec6156b..9ebd4a38d125f538583355e90cfa8c8ff1adbca3 100755 (executable)
@@ -22,6 +22,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <system_info.h>
+#include <hal-wifi.h>
 
 #include "log.h"
 #include "util.h"
@@ -147,6 +148,10 @@ int main(int argc, char *argv[])
         * Execute only when the old style hal architecture is not running
         */
        if (!wifi_check_systemd_service()) {
+               ret = hal_wifi_get_backend();
+               if (ret < 0)
+                       DBG("hal_wifi_get_backend() failed, ret: %d", ret);
+
                ifname = netconfig_get_default_ifname_from_file();
 
                if (ifname && netconfig_wifi_firmware_get_mac(ifname, &wifi_def_mac) == 0)
@@ -225,5 +230,9 @@ int main(int argc, char *argv[])
        /* Unregistering the agent */
        connman_unregister_agent();
 
+       ret = hal_wifi_put_backend();
+       if (ret < 0)
+               DBG("hal_wifi_put_backend() failed, ret: %d", ret);
+
        return 0;
 }
index 887bf253127729fea457a52694f52a5c5b6d5e56..325332d13a96e9e658677e60e47b3c924317e187 100755 (executable)
@@ -126,11 +126,6 @@ static int __netconfig_sta_firmware_start(const char *interface_name)
        int if_found = 0;
 
        if_found = wifi_check_interface(interface_name);
-       rv = hal_wifi_get_backend();
-       if (rv < 0 && !if_found) {
-               DBG("hal_wifi_get_backend() failed, ret: %d", rv);
-               return -EIO;
-       }
 
        rv = hal_wifi_sta_start(interface_name);
        if (rv < 0 && !if_found) {
@@ -154,12 +149,6 @@ static int __netconfig_sta_firmware_stop(const char *interface_name)
        if (rv != TRUE)
                return -EIO;
 
-       rv = hal_wifi_get_backend();
-       if (rv < 0) {
-               DBG("hal_wifi_get_backend() failed, ret: %d", rv);
-               return -EIO;
-       }
-
        rv = hal_wifi_stop(interface_name);
        if (rv < 0) {
                DBG("hal_wifi_stop() failed, ret: %d", rv);
@@ -180,11 +169,6 @@ static int __netconfig_p2p_firmware_start(const char *interface_name)
        int if_found = 0;
 
        if_found = wifi_check_interface(interface_name);
-       rv = hal_wifi_get_backend();
-       if (rv < 0 && !if_found) {
-               DBG("hal_wifi_get_backend() failed, ret: %d", rv);
-               return -EIO;
-       }
 
        rv = hal_wifi_p2p_start(interface_name);
        if (rv < 0 && !if_found) {
@@ -213,12 +197,6 @@ static int __netconfig_p2p_firmware_stop(const char *interface_name)
        if (rv != TRUE)
                return -EIO;
 
-       rv = hal_wifi_get_backend();
-       if (rv < 0) {
-               DBG("hal_wifi_get_backend() failed, ret: %d", rv);
-               return -EIO;
-       }
-
        rv = hal_wifi_stop(interface_name);
        if (rv < 0) {
                DBG("hal_wifi_stop() failed, ret: %d", rv);
@@ -240,11 +218,6 @@ static int __netconfig_softap_firmware_start(const char *interface_name)
        int if_found = 0;
 
        if_found = wifi_check_interface(interface_name);
-       rv = hal_wifi_get_backend();
-       if (rv < 0 && !if_found) {
-               DBG("hal_wifi_get_backend() failed, ret: %d", rv);
-               return -EIO;
-       }
 
        rv = hal_wifi_softap_start(interface_name);
        if (rv < 0 && !if_found) {
@@ -271,12 +244,6 @@ static int __netconfig_softap_firmware_stop(const char *interface_name)
        if (rv != TRUE)
                return -EIO;
 
-       rv = hal_wifi_get_backend();
-       if (rv < 0) {
-               DBG("hal_wifi_get_backend() failed, ret: %d", rv);
-               return -EIO;
-       }
-
        rv = hal_wifi_stop(interface_name);
        if (rv < 0) {
                DBG("hal_wifi_stop() failed, ret: %d", rv);
@@ -402,12 +369,6 @@ int netconfig_wifi_firmware_get_mac(const char *interface_name, char **mac)
 {
        int rv = 0;
 
-       rv = hal_wifi_get_backend();
-       if (rv < 0) {
-               DBG("hal_wifi_get_backend() failed, ret: %d", rv);
-               return -EIO;
-       }
-
        rv = hal_wifi_get_mac(interface_name, mac);
        if (rv < 0) {
                DBG("hal_wifi_get_mac() failed, ret: %d", rv);