From 4cbdeeaa6b15602df3e9bacf53e4295cf39ad602 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Mon, 29 Mar 2021 11:02:10 +0900 Subject: [PATCH] Fix defects detected by static analysis tool Change-Id: I63d6070426e1782484ba683979e16e3eff4d06fe --- src/service_config.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/service_config.cpp b/src/service_config.cpp index 2f2bc27..cdf1687 100644 --- a/src/service_config.cpp +++ b/src/service_config.cpp @@ -311,20 +311,23 @@ int CServiceConfig::load_custom_wake_words(const char* app_id, preference_is_existing("custom_wakeup_languages", &existing); if (!existing) return -1; - char* value = NULL; - preference_get_string("custom_wakeup_words", &value); - if (NULL == value) return -1; - strncpy(wakeup_words, value, sizeof(wakeup_words) - 1); + char* custom_wakeup_words = NULL; + preference_get_string("custom_wakeup_words", &custom_wakeup_words); + if (NULL == custom_wakeup_words) return -1; + strncpy(wakeup_words, custom_wakeup_words, sizeof(wakeup_words) - 1); wakeup_words[sizeof(wakeup_words) - 1] = '\0'; LOGD("Custom wakeup words loaded : %s", wakeup_words); - free(value); + free(custom_wakeup_words); + custom_wakeup_words = NULL; - preference_get_string("custom_wakeup_languages", &value); - if (NULL == value) return -1; - strncpy(wakeup_languages, value, sizeof(wakeup_languages) - 1); + char* custom_wakeup_languages = NULL; + preference_get_string("custom_wakeup_languages", &custom_wakeup_languages); + if (NULL == custom_wakeup_languages) return -1; + strncpy(wakeup_languages, custom_wakeup_languages, sizeof(wakeup_languages) - 1); wakeup_languages[sizeof(wakeup_languages) - 1] = '\0'; LOGD("Custom wakeup languages loaded : %s", wakeup_languages); - free(value); + free(custom_wakeup_languages); + custom_wakeup_languages = NULL; char *word_start = wakeup_words; char *language_start = wakeup_languages; -- 2.7.4