d2d-conv-setting : fix svace issue 59/114459/1 accepted/tizen/3.0/mobile/20170215.033644 submit/tizen_3.0/20170214.004548
authorSegwon <segwon.han@samsung.com>
Mon, 13 Feb 2017 10:44:58 +0000 (19:44 +0900)
committerSegwon <segwon.han@samsung.com>
Mon, 13 Feb 2017 10:45:28 +0000 (19:45 +0900)
Pointer variable obtained from conv_device_get_property_string() was allocated.
Added free function to prevent memory leak.

Signed-off-by: Segwon <segwon.han@samsung.com>
Change-Id: I9872ab9ae254727ded020d0ce84a0f2d2e8c485a

src/ui/setting_item_device_list.c

index 535f260..a125126 100644 (file)
@@ -264,18 +264,22 @@ static void discovery_foreach_cb(conv_device_h device_h, int result, void *data)
        case CONV_DISCOVERY_RESULT_SUCCESS :
 
                conv_device_get_property_string(device_h, CONV_DEVICE_ID, &device_id);
+               conv_device_get_property_string(device_h, CONV_DEVICE_NAME, &device_name);
+               conv_device_get_property_string(device_h, CONV_DEVICE_TYPE, &device_type);
+
+               if (device_id == NULL | device_name == NULL | device_type == NULL) {
+                       goto MEMORY_FREE;
+               }
+
                int device_id_index;
                for (device_id_index = 0; device_id_index < 5; device_id_index++) {
                        device_id[2+(device_id_index*3)] = '-';
                }
 
-               conv_device_get_property_string(device_h, CONV_DEVICE_NAME, &device_name);
-               conv_device_get_property_string(device_h, CONV_DEVICE_TYPE, &device_type);
-
                int index;
                for (index = 0; index <= discovered_devices_index; index++) {
                        if (!strcmp(discovered_devices_info[index]->mac_address, device_id)) {
-                               return;
+                               goto MEMORY_FREE;
                        }
                }
 
@@ -290,6 +294,16 @@ static void discovery_foreach_cb(conv_device_h device_h, int result, void *data)
                elm_genlist_item_append(discovered_list, device_item_builder, discovered_devices_info[index], discovered_device_group, ELM_GENLIST_ITEM_NONE, device_list_select_cb, discovered_devices_info[index]);
                elm_genlist_item_fields_update(discovered_device_group, "elm.swallow.end", ELM_GENLIST_ITEM_FIELD_CONTENT);
 
+MEMORY_FREE:
+               if (device_id != NULL) {
+                       free(device_id);
+               }
+               if (device_name != NULL) {
+                       free(device_name);
+               }
+               if (device_type != NULL) {
+                       free(device_type);
+               }
                return;
 
        case CONV_DISCOVERY_RESULT_FINISHED :