Fixed memory leaks while using Tizen CAPI
authorSaurav Babu <saurav.babu@samsung.com>
Tue, 23 Feb 2016 11:47:32 +0000 (17:17 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Thu, 25 Feb 2016 00:44:01 +0000 (00:44 +0000)
wifi_ap_get_ip_address() returns string with allocated memory, this
patch frees the memory if it was allocated earlier.
wifi_ap_get_essid() returns string with allocated memory, this patch
frees the memory after its use

Change-Id: Ieb6adbabca8317ab66f0efddf8635d4a1693c662
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5157
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/easy-setup/enrollee/tizen/wifi/networkhandler.cpp

index ab4d54f..ac6f205 100644 (file)
@@ -29,7 +29,7 @@
 
 const char *gSsid = "DLNA_LISMORE1";
 const char *gPass = "dlna@010203";
-char *gIpAddress;
+char *gIpAddress = NULL;
 wifi_ap_h connectedWifi;
 NetworkEventCallback gNetworkEventCb;
 static void ESActivateWifi();
@@ -53,6 +53,10 @@ print_state(wifi_connection_state_e state)
 void __wifi_connected_cb(wifi_error_e error_code, void *user_data)
 {
     OIC_LOG(INFO,LOG_TAG,"#### __connected ");
+
+    if (gIpAddress)
+        free(gIpAddress);
+
     wifi_ap_get_ip_address(connectedWifi, WIFI_ADDRESS_FAMILY_IPV4, &gIpAddress);
     OIC_LOG_V(INFO,LOG_TAG,"#### __connected, Ipaddress=%s", gIpAddress);
     gNetworkEventCb(ES_OK);
@@ -78,6 +82,7 @@ bool __wifi_found_ap_cb(wifi_ap_h ap, void *user_data)
     if (error_code != WIFI_ERROR_NONE)
     {
         OIC_LOG(ERROR,LOG_TAG,"#### Fail to get state.");
+        free(ap_name);
 
         return false;
     }
@@ -92,6 +97,7 @@ bool __wifi_found_ap_cb(wifi_ap_h ap, void *user_data)
         OIC_LOG_V(INFO,LOG_TAG,"Code=%d", error_code);
     }
     OIC_LOG(INFO,LOG_TAG,"#### __wifi_found_ap_cb received ");
+    free(ap_name);
     return true;
 }
 void __scan_request_cb(wifi_error_e error_code, void *user_data)