Fix Svace & coverty issues 62/212262/2 accepted/tizen_5.5_unified accepted/tizen_5.5_unified_mobile_hotfix accepted/tizen_5.5_unified_wearable_hotfix accepted/tizen_6.0_unified accepted/tizen_6.0_unified_hotfix accepted/tizen_6.5_unified tizen_5.5 tizen_5.5_mobile_hotfix tizen_5.5_tv tizen_5.5_wearable_hotfix tizen_6.0 tizen_6.0_hotfix tizen_6.5 accepted/tizen/5.5/unified/20191031.024023 accepted/tizen/5.5/unified/mobile/hotfix/20201027.083940 accepted/tizen/5.5/unified/wearable/hotfix/20201027.114914 accepted/tizen/6.0/unified/20201030.120413 accepted/tizen/6.0/unified/hotfix/20201103.050246 accepted/tizen/6.5/unified/20211028.100312 accepted/tizen/unified/20190820.115003 submit/tizen/20190820.045040 submit/tizen_5.5/20191031.000003 submit/tizen_5.5_mobile_hotfix/20201026.185103 submit/tizen_5.5_wearable_hotfix/20201026.184303 submit/tizen_6.0/20201029.205103 submit/tizen_6.0_hotfix/20201102.192503 submit/tizen_6.0_hotfix/20201103.114803 submit/tizen_6.5/20211028.162201 tizen_5.5.m2_release tizen_6.0.m2_release tizen_6.5.m2_release
authorJung Jihoon <jh8801.jung@samsung.com>
Mon, 19 Aug 2019 11:10:06 +0000 (20:10 +0900)
committerJung Jihoon <jh8801.jung@samsung.com>
Tue, 20 Aug 2019 04:47:26 +0000 (13:47 +0900)
- Svace : 317229, 372690 DEREF_OF_NULL
- Coverity : 1043621104361610435931043590 Reasource leak

Change-Id: I1a48df4605fb8d48d74e40eb4f4e47ff711ffec1
Signed-off-by: Jung Jihoon <jh8801.jung@samsung.com>
src/mdg-manager/src/mdgd_iot.cpp
src/mdg-manager/src/mdgd_iot_server.cpp

index 8120b243665cc20f4fc7e1968c647682ea740e54..d0c170daf7d8f39988f1f766d0deb0464456f7e5 100755 (executable)
@@ -826,33 +826,49 @@ int mdgd_iot_initialize()
                OicUuid_t *uuid = &iter->doxm->deviceID;
                mdgd_uuid_to_str(uuid, &device_id);
 
-               if (g_strcmp0(mdgd_ctx->device_uuid, device_id) != 0) {
-                       iter = iter->next;
-                       continue;
+               if (g_strcmp0(mdgd_ctx->device_uuid, device_id) == 0) {
+                       char *device_name = NULL;
+                       char *model_name = NULL;
+                       char *platform_ver = NULL;
+                       char *profile = NULL;
+
+                       mdgd_device_t *device = (mdgd_device_t *)g_try_malloc0(sizeof(mdgd_device_t));
+                       if (device == NULL) {
+                               LOG_ERR("device is NULL");
+                               if (device_id != NULL)
+                                       free(device_id);
+
+                               break;
+                       }
+
+                       system_settings_get_value_string(SYSTEM_SETTINGS_KEY_DEVICE_NAME, &device_name);
+                       system_info_get_platform_string(SYSTEM_INFO_MODEL_NAME, &model_name);
+                       system_info_get_platform_string(SYSTEM_INFO_PLATFORM_VERSION, &platform_ver);
+                       system_info_get_platform_string(SYSTEM_INFO_PROFILE, &profile);
+
+                       device->device_id = device_id;
+                       device->device_name = g_strdup(device_name);
+                       device->model_name = g_strdup(model_name);
+                       device->platform_ver = g_strdup(platform_ver);
+                       device->profile = g_strdup(profile);
+                       device->vendor_id = g_strdup("6FFF");
+                       device->is_invited = true;
+                       device->type = MDGD_DEVICE_TYPE_LOCAL;
+
+                       mdgd_ctx->device = device;
+                       LOG_DEBUG("local device stored");
+
+                       g_free(device_name);
+                       g_free(model_name);
+                       g_free(platform_ver);
+                       g_free(profile);
+
+                       break;
                }
 
-               mdgd_device_t *device = (mdgd_device_t *)g_try_malloc0(sizeof(mdgd_device_t));
-               char *device_name = NULL;
-               char *model_name = NULL;
-               char *platform_ver = NULL;
-               char *profile = NULL;
-
-               system_settings_get_value_string(SYSTEM_SETTINGS_KEY_DEVICE_NAME, &device_name);
-               system_info_get_platform_string(SYSTEM_INFO_MODEL_NAME, &model_name);
-               system_info_get_platform_string(SYSTEM_INFO_PLATFORM_VERSION, &platform_ver);
-               system_info_get_platform_string(SYSTEM_INFO_PROFILE, &profile);
-
-               device->device_id = device_id;
-               device->device_name = g_strdup(device_name);
-               device->model_name = g_strdup(model_name);
-               device->platform_ver = g_strdup(platform_ver);
-               device->profile = g_strdup(profile);
-               device->vendor_id = g_strdup("6FFF");
-               device->is_invited = true;
-               device->type = MDGD_DEVICE_TYPE_LOCAL;
-
-               mdgd_ctx->device = device;
-               LOG_DEBUG("local device stored");
+               if (device_id != NULL)
+                       free(device_id);
+
                iter = iter->next;
        }
 
@@ -863,7 +879,17 @@ int mdgd_iot_deinitialize()
 {
        LOG_BEGIN();
 
-       //iot deinitiatlize
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+
+       if (mdgd_ctx->device_uuid != NULL) {
+               free(mdgd_ctx->device_uuid);
+               mdgd_ctx->device_uuid = NULL;
+       }
+
+       if (mdgd_ctx->device != NULL) {
+               mdgd_clean_device(mdgd_ctx->device);
+               mdgd_ctx->device = NULL;
+       }
 
        LOG_END();
 
index c7b4efed3d3191dec5fb2af33506bc0c0248fff1..43ac34e0b2bd971d3e3d7202bfa86492ec7f755c 100644 (file)
@@ -353,6 +353,10 @@ OCEntityHandlerResult _request_handler(std::shared_ptr<OCResourceRequest> reques
 
                                                if (sender != NULL) {
                                                        mdgd_channel_t *channel = (mdgd_channel_t *)g_try_malloc0(sizeof(mdgd_channel_t));
+                                                       if (channel == NULL) {
+                                                               LOG_ERR("channel is NULL");
+                                                               break;
+                                                       }
                                                        channel->device_id = g_strdup(requester_id.c_str());
                                                        channel->channel_id = g_strdup(channel_id.c_str());
                                                        channel->remote_address = g_strdup("TEMP");