Fix defects detected by coverity tool 73/319073/2 accepted/tizen/unified/20250305.160207 accepted/tizen/unified/x/20250306.020053
authordyamy-lee <dyamy.lee@samsung.com>
Tue, 4 Feb 2025 02:51:03 +0000 (11:51 +0900)
committerdyamy-lee <dyamy.lee@samsung.com>
Tue, 4 Feb 2025 03:18:21 +0000 (12:18 +0900)
To prevent memory leak, checking and freeing the variables before using strdup

Change-Id: I36d64d12d3a1568123549874571a35c9ecd0cda0

common/ma_config_mgr.c

index 2b2c38c1b99b18e60e44b5d1851efd0aa4f6e73a..ff4c5f60034f32cc5a166c45b24d152050be058d 100644 (file)
@@ -139,6 +139,10 @@ int ma_config_mgr_parse_assistant_info(ma_ui_assistant_info_cb callback, void* u
                } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_NAME)) {
                        key = xmlNodeGetContent(cur);
                        if (key) {
+                               if (temp->name) {
+                                       free((void*)temp->name);
+                                       temp->name = NULL;
+                               }
                                temp->name = strdup((const char*)key);
                                MA_SLOGD("Name : %s", key);
                                xmlFree(key);
@@ -146,6 +150,10 @@ int ma_config_mgr_parse_assistant_info(ma_ui_assistant_info_cb callback, void* u
                } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_APPID)) {
                        key = xmlNodeGetContent(cur);
                        if (key) {
+                               if (temp->app_id) {
+                                       free((void*)temp->app_id);
+                                       temp->app_id = NULL;
+                               }
                                temp->app_id = strdup((const char*)key);
                                MA_SLOGD("ID : %s", key);
                                xmlFree(key);
@@ -153,6 +161,10 @@ int ma_config_mgr_parse_assistant_info(ma_ui_assistant_info_cb callback, void* u
                } else if (cur->name && 0 == xmlStrcmp(cur->name, (const xmlChar*)MA_TAG_ASSISTANT_ICON_PATH)) {
                        key = xmlNodeGetContent(cur);
                        if (key) {
+                               if (temp->icon_path) {
+                                       free((void*)temp->icon_path);
+                                       temp->icon_path = NULL;
+                               }
                                temp->icon_path = strdup((const char*)key);
                                MA_SLOGD("Icon Path : %s", key);
                                xmlFree(key);