From c587d91c4301303774e2377c8cf66a2667e5b338 Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Tue, 4 Feb 2025 11:51:03 +0900 Subject: [PATCH] Fix defects detected by coverity tool To prevent memory leak, checking and freeing the variables before using strdup Change-Id: I36d64d12d3a1568123549874571a35c9ecd0cda0 --- common/ma_config_mgr.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/common/ma_config_mgr.c b/common/ma_config_mgr.c index 2b2c38c..ff4c5f6 100644 --- a/common/ma_config_mgr.c +++ b/common/ma_config_mgr.c @@ -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); -- 2.34.1