[Fix] Remove restriction from tree when user initiated remove operation
[platform/core/connectivity/stc-manager.git] / src / stc-manager-util.c
index 1c97e81..b929427 100755 (executable)
@@ -40,10 +40,10 @@ static GKeyFile *__load_key_file(const char *path)
        keyfile = g_key_file_new();
 
        if (!g_key_file_load_from_file(keyfile, path, 0, &error)) {
-               STC_LOGD("Unable to load [%s] : %s", path, error->message);
-               g_clear_error(&error);
-               g_key_file_free(keyfile);
-               keyfile = NULL;
+               STC_LOGD("Unable to load [%s] : %s", path, error->message); //LCOV_EXCL_LINE
+               g_clear_error(&error); //LCOV_EXCL_LINE
+               g_key_file_free(keyfile); //LCOV_EXCL_LINE
+               keyfile = NULL; //LCOV_EXCL_LINE
        }
 
        return keyfile;
@@ -59,9 +59,9 @@ static int __save_key_file(GKeyFile *keyfile, char *path)
        data = g_key_file_to_data(keyfile, &length, NULL);
 
        if (!g_file_set_contents(path, data, length, &error)) {
-               STC_LOGD("Failed to save information : %s", error->message);
-               g_error_free(error);
-               ret = -EIO;
+               STC_LOGD("Failed to save information : %s", error->message); //LCOV_EXCL_LINE
+               g_error_free(error); //LCOV_EXCL_LINE
+               ret = -EIO; //LCOV_EXCL_LINE
        }
 
        __sync_file_to_disk(path);
@@ -70,10 +70,12 @@ static int __save_key_file(GKeyFile *keyfile, char *path)
        return ret;
 }
 
+//LCOV_EXCL_START
 gboolean stc_util_get_config_bool(char *key)
 {
        char path[MAX_PATH_LENGTH];
        GKeyFile *keyfile;
+       gboolean value;
 
        snprintf(path, sizeof(path), "%s/%s", INFO_STORAGE_DIR, INFO_CONFIG);
 
@@ -81,13 +83,17 @@ gboolean stc_util_get_config_bool(char *key)
        if (!keyfile)
                keyfile = g_key_file_new();
 
-       return g_key_file_get_boolean(keyfile, path, key, NULL);
+       value = g_key_file_get_boolean(keyfile, path, key, NULL);
+       g_key_file_free(keyfile);
+
+       return value;
 }
 
 gchar * stc_util_get_config_str(char *key)
 {
        char path[MAX_PATH_LENGTH];
        GKeyFile *keyfile;
+       gchar *value;
 
        snprintf(path, sizeof(path), "%s/%s", INFO_STORAGE_DIR, INFO_CONFIG);
 
@@ -95,27 +101,38 @@ gchar * stc_util_get_config_str(char *key)
        if (!keyfile)
                keyfile = g_key_file_new();
 
-       return g_key_file_get_string(keyfile, path, key, NULL);
+       value = g_key_file_get_string(keyfile, path, key, NULL);
+       g_key_file_free(keyfile);
+
+       return value;
 }
+//LCOV_EXCL_STOP
 
 int stc_util_get_config_int(char *key)
 {
        char path[MAX_PATH_LENGTH];
        GKeyFile *keyfile;
+       gint value;
 
        snprintf(path, sizeof(path), "%s/%s", INFO_STORAGE_DIR, INFO_CONFIG);
 
        keyfile = __load_key_file(path);
        if (!keyfile)
-               keyfile = g_key_file_new();
+               keyfile = g_key_file_new(); //LCOV_EXCL_LINE
 
-       return g_key_file_get_integer(keyfile, path, key, NULL);
+
+       value = g_key_file_get_integer(keyfile, path, key, NULL);
+       g_key_file_free(keyfile);
+
+       return value;
 }
 
+//LCOV_EXCL_START
 API void stc_util_set_debuglog(int debuglog)
 {
        g_debuglog = debuglog;
 }
+//LCOV_EXCL_STOP
 
 API int stc_util_get_debuglog(void)
 {
@@ -134,7 +151,7 @@ void stc_util_initialize_config(void)
 
        keyfile = __load_key_file(path);
        if (!keyfile)
-               keyfile = g_key_file_new();
+               keyfile = g_key_file_new(); //LCOV_EXCL_LINE
 
        g_key_file_set_integer(keyfile, path, INFO_DEBUGLOG, 0);