Fix issue detected by static analysis tool 23/248623/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Tue, 1 Dec 2020 03:47:50 +0000 (12:47 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Tue, 1 Dec 2020 03:48:03 +0000 (12:48 +0900)
Dynamic memory referenced by 'pref_str' was allocated at preference.c:1245
by calling function 'preference_get_string' at config.cpp:74 and lost at config.cpp:75.

Change-Id: I5f7a6f24701a8e4730daeb24903f78fafd3c142f
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/config.cpp

index ecde389..2f05e35 100644 (file)
@@ -72,8 +72,10 @@ void read_ise_config_string(const char *key, std::string &value)
     int ret;
 
     ret = preference_get_string(key, &pref_str);
-    if (ret == PREFERENCE_ERROR_NONE && pref_str) {
-        value.assign(pref_str, strlen(pref_str));
+    if (pref_str) {
+        if (ret == PREFERENCE_ERROR_NONE)
+            value.assign(pref_str, strlen(pref_str));
+
         free(pref_str);
     }
 }