Fix svace issues 61/199961/5
authorJihoon Jung <jh8801.jung@samsung.com>
Mon, 18 Feb 2019 02:24:40 +0000 (11:24 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 18 Feb 2019 04:04:07 +0000 (13:04 +0900)
- 410071: fixed memory leak problem due to dynamic allocated 'devices'
- 410077: fixed memory leak that is not freed because the dynamic
allocated 'cmd' variable is called through multiple callback function.
- 410083: fixed memory leak that do not free 'uuid_str' variable which
allocated by g_strdup().
- 410084: fixed a problem that does not free the variables allocated to
heap during mdgd_iot_initialize() when calling mdgd_iot_deinitialize()

Change-Id: I88e824bac894ae2f51c8310109d1242c36737c70
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
src/mdg-manager/include/mdgd_util.h [changed mode: 0644->0755]
src/mdg-manager/src/mdgd_group.c
src/mdg-manager/src/mdgd_iot.cpp
src/mdg-manager/src/mdgd_iot_client.cpp

old mode 100644 (file)
new mode 100755 (executable)
index d6f486a..42ae93a
@@ -47,6 +47,7 @@ mdgd_device_t *mdgd_get_device_from_variant(GVariant *va);
 int mdgd_util_get_msg_id();
 void mdgd_util_data_encode(const char *data, int data_len, char **encoded_data, int *encoded_len);
 void mdgd_util_data_decode(const char *data, int data_len, char **decoded_data, int *decoded_len);
+
 #ifdef __cplusplus
 }
 #endif
index 6c6ca4ec89559839211628f276f8159c39e9ad36..33435c7f7a7c40537745aaa10291a70a1c29d709 100644 (file)
@@ -43,7 +43,7 @@ int mdgd_group_create(const char *name)
 int mdgd_group_delete(char *name)
 {
        int ret = MDGD_ERROR_NONE;
-       mdgd_device_t **devices;
+       mdgd_device_t **devices = NULL;
        int device_count = 0;
 
        LOG_BEGIN();
@@ -55,11 +55,15 @@ int mdgd_group_delete(char *name)
 
                if (mdgd_db_check_device_exist((char *)devices[i]) == false)
                        mdgd_iot_unpair(name, devices[i]->device_id);
+               mdgd_clean_device(devices[i]);
        }
 
        /* delete group */
        mdgd_db_group_delete(name);
 
+       if (devices != NULL)
+               g_free(devices);
+
        LOG_END();
 
        return ret;
@@ -83,6 +87,8 @@ static gboolean __timeout_cb(gpointer data)
        else
                LOG_ERR("Unknown Resource Type");
 
+       mdgd_clean_user_data(data);
+
        LOG_END();
 
        return G_SOURCE_REMOVE;
index abfbbd6f8677dc88d86ed0159887b294a72ac568..5fd2f1835120d08491d7178350be4904f1a78d16 100644 (file)
@@ -342,7 +342,17 @@ int mdgd_iot_find_devices(char *sender, int timeout, bool is_invited)
                }
 
                mdgd_command_t *cmd = (mdgd_command_t *)g_try_malloc0(sizeof(mdgd_command_t));
+               if (cmd == NULL) {
+                       LOG_ERR("cmd allocated failed");
+                       continue;
+               }
+
                mdgd_device_t *device = (mdgd_device_t *)g_try_malloc0(sizeof(mdgd_device_t));
+               if (device == NULL) {
+                       LOG_ERR("device allocated failed");
+                       g_free(cmd);
+                       continue;
+               }
 
                int port = selDev->endpoint.port;
                int conn_type = selDev->connType;
@@ -359,6 +369,7 @@ int mdgd_iot_find_devices(char *sender, int timeout, bool is_invited)
 
                g_free(addr);
                g_free(host_addr);
+               free(uuid_str);
        }
 
        return result;
@@ -745,6 +756,11 @@ int mdgd_iot_initialize()
                }
 
                mdgd_device_t *device = (mdgd_device_t *)g_try_malloc0(sizeof(mdgd_device_t));
+               if (device == NULL) {
+                       LOG_ERR("device allocated failed");
+                       continue;
+               }
+
                char *device_name = NULL;
                char *model_name = NULL;
                char *platform_ver = NULL;
@@ -776,7 +792,36 @@ int mdgd_iot_deinitialize()
 {
        LOG_BEGIN();
 
-       //iot deinitiatlize
+       mdgd_context_t *mdgd_ctx = mdgd_context_get_context();
+       mdgd_check_null_ret_error("mdgd_ctx", mdgd_ctx, MDGD_ERROR_INVALID_PARAMETER);
+
+       if (mdgd_ctx->device) {
+               if (mdgd_ctx->device->device_id) {
+                       free(mdgd_ctx->device->device_id);
+                       mdgd_ctx->device->device_id = NULL;
+               }
+
+               if (mdgd_ctx->device->model_name) {
+                       g_free(mdgd_ctx->device->model_name);
+                       mdgd_ctx->device->model_name = NULL;
+               }
+
+               if (mdgd_ctx->device->device_name) {
+                       g_free(mdgd_ctx->device->device_name);
+                       mdgd_ctx->device->device_name = NULL;
+               }
+
+               if (mdgd_ctx->device->platform_ver) {
+                       g_free(mdgd_ctx->device->platform_ver);
+                       mdgd_ctx->device->platform_ver = NULL;
+               }
+
+               if (mdgd_ctx->device->vendor_id) {
+                       g_free(mdgd_ctx->device->vendor_id);
+                       mdgd_ctx->device->vendor_id = NULL;
+               }
+       }
+
 
        LOG_END();
 
index 58474458a87f81b266d73690ef9c76b88adc5df2..f2d369b44f9c60eb42867513704094e2e341dc56 100644 (file)
@@ -234,6 +234,8 @@ static void __get_group_information(const HeaderOptions &headerOptions,
                LOG_ERR("Exception %s in on get", e.what());
        }
 
+       mdgd_clean_user_data(user_data);
+
        LOG_END();
 }
 
@@ -334,6 +336,8 @@ static void __send_data_finish(const HeaderOptions &,
 
        mdgd_context_mutex_unlock();
 
+       mdgd_clean_user_data(user_data);
+
        LOG_END();
 }
 
@@ -374,6 +378,8 @@ static void __request_finish(const HeaderOptions &,
                LOG_ERR("Exception %s in on get", e.what());
        }
 
+       mdgd_clean_user_data(user_data);
+
        LOG_END();
 }
 
@@ -421,6 +427,9 @@ static bool _found_resource(std::shared_ptr<OCResource> resource,
                                rep.setValue("GroupName", std::string(cmd->arg1));
 
                                resource->put(rep, QueryParamsMap(), std::bind(&__send_event_finish, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
+
+                               mdgd_clean_user_data(user_data);
+
                        } else if (g_strcmp0(resource_type,
                                             mdgd_resource_get_type(MDGD_RESOURCE_TYPE_DATA)) == 0 &&
                                   g_strcmp0(cmd->uuid, resource->sid().c_str()) == 0) {
@@ -575,6 +584,8 @@ void __get_device_description(const HeaderOptions &headerOptions,
                LOG_ERR("Exception %s in on get", e.what());
        }
 
+       mdgd_clean_user_data(user_data);
+
        LOG_END();
 }