Fix memory leak / Define memory free macro 97/123397/1
authorSuyeon Hwang <stom.hwang@samsung.com>
Thu, 16 Feb 2017 05:11:28 +0000 (14:11 +0900)
committerKwangyoun Kim <ky85.kim@samsung.com>
Wed, 5 Apr 2017 10:22:42 +0000 (03:22 -0700)
Change-Id: I86a9dc04238f0cfd123be20785adf7be7ce8e96a
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
(cherry picked from commit 3a6e7970b0a713fd707c1a620ed99d73945895d1)

engine-parser/src/stt-engine-parser.c

index 281818c..8c4b201 100644 (file)
 #define STT_METADATA_ENGINE_SETTING            "http://tizen.org/metadata/stt-engine/setting"
 #define STT_METADATA_ENGINE_NAME               "http://tizen.org/metadata/stt-engine/name"
 
+/* Define Macro */
+#define FREE(x)        { if (NULL != x)        { free(x);      x = NULL; } }
+#define G_FREE(x)      { if (NULL != x) { g_free(x);   x = NULL; } }
+
 typedef struct metadata {
        const char *key;
        const char *value;
@@ -140,41 +144,27 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
 
        if (NULL == dir_config_base || NULL == dir_home || NULL == dir_engine_base || NULL == dir_engine_info) {
                LOGE("[ERROR] Fail to allocate memory");
-               if (NULL != dir_config_base) {
-                       free(dir_config_base);
-                       dir_config_base = NULL;
-               }
-               if (NULL != dir_home) {
-                       free(dir_home);
-                       dir_home = NULL;
-               }
-               if (NULL != dir_engine_base) {
-                       free(dir_engine_base);
-                       dir_engine_base = NULL;
-               }
-               if (NULL != dir_engine_info) {
-                       free(dir_engine_info);
-                       dir_engine_info = NULL;
-               }
+               FREE(dir_config_base)
+               FREE(dir_home)
+               FREE(dir_engine_base)
+               FREE(dir_engine_info)
                return -1;
        }
 
        LOGD("[DEBUG] dir_engine_info(%s)", dir_engine_info);
 
        /* Make directories */
+       int fd = -1;
 //     if (0 != access(dir_config_base, F_OK)) {
-       if (-1 == open(dir_config_base, O_DIRECTORY)) {
+       fd = open(dir_config_base, O_DIRECTORY);
+       if (-1 == fd) {
                LOGE("[INFO] No directory : %s, errno : %d", dir_config_base, errno);
                if (0 != mkdir(dir_config_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
                        LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_config_base, errno);
-                       free(dir_config_base);
-                       dir_config_base = NULL;
-                       free(dir_home);
-                       dir_home = NULL;
-                       free(dir_engine_base);
-                       dir_engine_base = NULL;
-                       free(dir_engine_info);
-                       dir_engine_info = NULL;
+                       FREE(dir_config_base)
+                       FREE(dir_home)
+                       FREE(dir_engine_base)
+                       FREE(dir_engine_info)
                        return -1;
                } else {
                        LOGD("Success to make directory : %s", dir_config_base);
@@ -184,21 +174,20 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
+       } else {
+               close(fd);
        }
 
 //     if (0 != access(dir_home, F_OK)) {
-       if (-1 == open(dir_home, O_DIRECTORY)) {
+       fd = open(dir_home, O_DIRECTORY);
+       if (-1 == fd) {
                LOGE("[INFO] No directory : %s, errno : %d", dir_home, errno);
                if (0 != mkdir(dir_home, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
                        LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_home, errno);
-                       free(dir_config_base);
-                       dir_config_base = NULL;
-                       free(dir_home);
-                       dir_home = NULL;
-                       free(dir_engine_base);
-                       dir_engine_base = NULL;
-                       free(dir_engine_info);
-                       dir_engine_info = NULL;
+                       FREE(dir_config_base)
+                       FREE(dir_home)
+                       FREE(dir_engine_base)
+                       FREE(dir_engine_info)
                        return -1;
                } else {
                        LOGD("Success to make directory : %s", dir_home);
@@ -208,21 +197,20 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
+       } else {
+               close(fd);
        }
 
 //     if (0 != access(dir_engine_base, F_OK)) {
-       if (-1 == open(dir_engine_base, O_DIRECTORY)) {
+       fd = open(dir_engine_base, O_DIRECTORY);
+       if (-1 == fd) {
                LOGE("[INFO] No directory : %s, errno : %d", dir_engine_base, errno);
                if (0 != mkdir(dir_engine_base, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
                        LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_engine_base, errno);
-                       free(dir_config_base);
-                       dir_config_base = NULL;
-                       free(dir_home);
-                       dir_home = NULL;
-                       free(dir_engine_base);
-                       dir_engine_base = NULL;
-                       free(dir_engine_info);
-                       dir_engine_info = NULL;
+                       FREE(dir_config_base)
+                       FREE(dir_home)
+                       FREE(dir_engine_base)
+                       FREE(dir_engine_info)
                        return -1;
                } else {
                        LOGD("Success to make directory : %s", dir_engine_base);
@@ -232,21 +220,20 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
+       } else {
+               close(fd);
        }
 
 //     if (0 != access(dir_engine_info, F_OK)) {
-       if (-1 == open(dir_engine_info, O_DIRECTORY)) {
+       fd = open(dir_engine_info, O_DIRECTORY);
+       if (-1 == fd) {
                LOGE("[INFO] No directory : %s, errno : %d", dir_engine_info, errno);
                if (0 != mkdir(dir_engine_info, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) {
                        LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_engine_info, errno);
-                       free(dir_config_base);
-                       dir_config_base = NULL;
-                       free(dir_home);
-                       dir_home = NULL;
-                       free(dir_engine_base);
-                       dir_engine_base = NULL;
-                       free(dir_engine_info);
-                       dir_engine_info = NULL;
+                       FREE(dir_config_base)
+                       FREE(dir_home)
+                       FREE(dir_engine_base)
+                       FREE(dir_engine_info)
                        return -1;
                } else {
                        LOGD("Success to make directory : %s", dir_engine_info);
@@ -256,6 +243,8 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
+       } else {
+               close(fd);
        }
 
        char path[256] = {'\0',};
@@ -270,14 +259,10 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
                }
        }
 
-       free(dir_config_base);
-       dir_config_base = NULL;
-       free(dir_home);
-       dir_home = NULL;
-       free(dir_engine_base);
-       dir_engine_base = NULL;
-       free(dir_engine_info);
-       dir_engine_info = NULL;
+       FREE(dir_config_base)
+       FREE(dir_home)
+       FREE(dir_engine_base)
+       FREE(dir_engine_info)
 
        LOGD("===");
 
@@ -323,10 +308,7 @@ static int __remove_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
                }
        }
 
-       if (NULL != dir_engine_info) {
-               free(dir_engine_info);
-               dir_engine_info = NULL;
-       }
+       FREE(dir_engine_info)
 
        LOGD("===");
 
@@ -338,6 +320,11 @@ static void __insert_language_from_metadata(xmlNodePtr root, const char *languag
        LOGD("==== Insert language");
        char* lang = NULL;
 
+       if (NULL == root || NULL == language) {
+               LOGE("Invalid parameter, root(%p), language(%s)", root, language);
+               return;
+       }
+
        char *tmp_lang, *tmp_free;
        tmp_free = tmp_lang = strdup(language);
        xmlNodePtr languages_node = NULL;
@@ -355,7 +342,7 @@ static void __insert_language_from_metadata(xmlNodePtr root, const char *languag
        }
        xmlAddChild(root, languages_node);
 
-       free(tmp_free);
+       FREE(tmp_free)
 }
 
 static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *list)
@@ -460,7 +447,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                LOGE("[ERROR] Fail to get target uid");
                g_object_unref(g_guser);
                g_guser = NULL;
-               g_free(g_user_type);
+               G_FREE(g_user_type)
                return -1;
        }
 
@@ -469,14 +456,14 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                LOGD("[DEBUG] usertype: %s", g_user_type);
                if (0 >= g_list_length(list)) {
                        LOGE("[ERROR] No Engine Metadata");
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return 0;
                }
 
                if (0 != __write_metadata_inxml(pkgid, appid, list)) {
                        LOGE("[ERROR] Fail to write metadata in the xml");
                        xmlFreeDoc(g_doc);
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -488,31 +475,19 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
 
                if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
                        LOGE("[ERROR] Fail to allocate memory");
-                       if (NULL != g_dir_config_base) {
-                               free(g_dir_config_base);
-                               g_dir_config_base = NULL;
-                       }
-                       if (NULL != g_dir_home) {
-                               free(g_dir_home);
-                               g_dir_home = NULL;
-                       }
-                       if (NULL != g_dir_engine_base) {
-                               free(g_dir_engine_base);
-                               g_dir_engine_base = NULL;
-                       }
-                       if (NULL != g_dir_engine_info) {
-                               free(g_dir_engine_info);
-                               g_dir_engine_info = NULL;
-                       }
+                       FREE(g_dir_config_base)
+                       FREE(g_dir_home)
+                       FREE(g_dir_engine_base)
+                       FREE(g_dir_engine_info)
                        xmlFreeDoc(g_doc);
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
                if (0 != __save_engine_info_xml(pkgid, g_user_type, g_uid, g_gid)) {
                        LOGE("[ERROR] Fail to make engine info file");
                        xmlFreeDoc(g_doc);
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -533,7 +508,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                gus = gum_user_service_create_sync(TRUE);
                if (!gus) {
                        LOGE("Failed to create gum user service");
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -546,7 +521,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                        LOGE("Failed to get gum user list");
                        g_object_unref(gus);
                        gus = NULL;
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -556,16 +531,15 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                while (iter != NULL) {
                        user = (GumUser*) iter->data;
                        g_object_get(G_OBJECT(user), "uid", &uid, NULL);
-                       if (NULL != home_dir) {
-                               free(home_dir);
-                               home_dir = NULL;
-                       }
+                       G_FREE(home_dir)
+
                        g_object_get(G_OBJECT(user), "gid", &gid, NULL);
                        g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
                        g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
                        user_type = g_strdup(gum_user_type_to_string(gumut));
                        if (NULL == user_type) {
                                gum_user_service_list_free(users);
+                               G_FREE(home_dir)
                                g_object_unref(gus);
                                gus = NULL;
                                return -1;
@@ -582,25 +556,15 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
 
                                if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
                                        LOGE("[ERROR] Fail to allocate memory");
-                                       if (NULL != g_dir_config_base) {
-                                               free(g_dir_config_base);
-                                               g_dir_config_base = NULL;
-                                       }
-                                       if (NULL != g_dir_home) {
-                                               free(g_dir_home);
-                                               g_dir_home = NULL;
-                                       }
-                                       if (NULL != g_dir_engine_base) {
-                                               free(g_dir_engine_base);
-                                               g_dir_engine_base = NULL;
-                                       }
-                                       if (NULL != g_dir_engine_info) {
-                                               free(g_dir_engine_info);
-                                               g_dir_engine_info = NULL;
-                                       }
+                                       FREE(g_dir_config_base)
+                                       FREE(g_dir_home)
+                                       FREE(g_dir_engine_base)
+                                       FREE(g_dir_engine_info)
                                        gum_user_service_list_free(users);
                                        g_object_unref(gus);
                                        gus = NULL;
+                                       G_FREE(user_type)
+                                       G_FREE(home_dir)
                                        return -1;
                                }
                                snprintf(g_dir_config_base, strlen(home_dir) + 14, "%s/share/.voice", home_dir);
@@ -614,29 +578,16 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                                        LOGE("[ERROR] Fail to make engine info file");
                                }
 
-                               free(g_dir_config_base);
-                               g_dir_config_base = NULL;
-                               free(g_dir_home);
-                               g_dir_home = NULL;
-                               free(g_dir_engine_base);
-                               g_dir_engine_base = NULL;
-                               free(g_dir_engine_info);
-                               g_dir_engine_info = NULL;
-
-                               g_free(user_type);
-                               user_type = NULL;
-                               free(home_dir);
-                               home_dir = NULL;
-
-                               iter = g_list_next(iter);
-                       } else {
-                               iter = g_list_next(iter);
-                       }
+                               FREE(g_dir_config_base)
+                               FREE(g_dir_home)
+                               FREE(g_dir_engine_base)
+                               FREE(g_dir_engine_info)
 
-                       if (NULL != user_type) {
-                               g_free(user_type);
-                               user_type = NULL;
+                               G_FREE(home_dir)
                        }
+
+                       G_FREE(user_type)
+                       iter = g_list_next(iter);
                }
 
                gum_user_service_list_free(users);
@@ -651,7 +602,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                        LOGE("[ERROR] Invalid uid");
                        g_object_unref(g_guser);
                        g_guser = NULL;
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return 0;
                } else {
                        LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
@@ -662,7 +613,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                        LOGE("[ERROR] No Engine Metadata");
                        g_object_unref(g_guser);
                        g_guser = NULL;
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return 0;
                }
 
@@ -671,7 +622,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                        xmlFreeDoc(g_doc);
                        g_object_unref(g_guser);
                        g_guser = NULL;
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -682,26 +633,14 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
 
                if (NULL == g_dir_config_base || NULL == g_dir_home || NULL == g_dir_engine_base || NULL == g_dir_engine_info) {
                        LOGE("[ERROR] Fail to allocate memory");
-                       if (NULL != g_dir_config_base) {
-                               free(g_dir_config_base);
-                               g_dir_config_base = NULL;
-                       }
-                       if (NULL != g_dir_home) {
-                               free(g_dir_home);
-                               g_dir_home = NULL;
-                       }
-                       if (NULL != g_dir_engine_base) {
-                               free(g_dir_engine_base);
-                               g_dir_engine_base = NULL;
-                       }
-                       if (NULL != g_dir_engine_info) {
-                               free(g_dir_engine_info);
-                               g_dir_engine_info = NULL;
-                       }
+                       FREE(g_dir_config_base)
+                       FREE(g_dir_home)
+                       FREE(g_dir_engine_base)
+                       FREE(g_dir_engine_info)
                        xmlFreeDoc(g_doc);
                        g_object_unref(g_guser);
                        g_guser = NULL;
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -712,7 +651,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                                g_object_unref(g_guser);
                                g_guser = NULL;
                        }
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
        }
@@ -722,24 +661,12 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                g_object_unref(g_guser);
                g_guser = NULL;
        }
-       g_free(g_user_type);
+       G_FREE(g_user_type)
 
-       if (NULL != g_dir_config_base) {
-               free(g_dir_config_base);
-               g_dir_config_base = NULL;
-       }
-       if (NULL != g_dir_home) {
-               free(g_dir_home);
-               g_dir_home = NULL;
-       }
-       if (NULL != g_dir_engine_base) {
-               free(g_dir_engine_base);
-               g_dir_engine_base = NULL;
-       }
-       if (NULL != g_dir_engine_info) {
-               free(g_dir_engine_info);
-               g_dir_engine_info = NULL;
-       }
+       FREE(g_dir_config_base)
+       FREE(g_dir_home)
+       FREE(g_dir_engine_base)
+       FREE(g_dir_engine_info)
 
        return 0;
 }
@@ -788,7 +715,7 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                LOGE("[ERROR] Fail to get target uid");
                g_object_unref(g_guser);
                g_guser = NULL;
-               g_free(g_user_type);
+               G_FREE(g_user_type)
                return -1;
        }
 
@@ -800,7 +727,7 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                g_dir_engine_info = strdup(STT_GLOBAL_ENGINE_INFO);
                if (NULL == g_dir_engine_info) {
                        LOGE("[ERROR] Fail to allocate memory");
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -827,7 +754,7 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                gus = gum_user_service_create_sync(TRUE);
                if (!gus) {
                        LOGE("Failed to create gum user service");
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -840,7 +767,7 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                        LOGE("Failed to get gum user list");
                        g_object_unref(gus);
                        gus = NULL;
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -850,15 +777,13 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                while (iter != NULL) {
                        user = (GumUser*) iter->data;
                        g_object_get(G_OBJECT(user), "uid", &uid, NULL);
-                       if (NULL != home_dir) {
-                               free(home_dir);
-                               home_dir = NULL;
-                       }
+                       G_FREE(home_dir)
                        g_object_get(G_OBJECT(user), "homedir", &home_dir, NULL);
                        g_object_get(G_OBJECT(user), "usertype", &gumut, NULL);
                        user_type = g_strdup(gum_user_type_to_string(gumut));
                        if (NULL == user_type) {
                                gum_user_service_list_free(users);
+                               G_FREE(home_dir)
                                g_object_unref(gus);
                                gus = NULL;
                                return -1;
@@ -868,8 +793,10 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                                g_dir_engine_info = (char*)calloc(strlen(home_dir) + 34, sizeof(char));
                                if (NULL == g_dir_engine_info) {
                                        gum_user_service_list_free(users);
+                                       G_FREE(home_dir)
                                        g_object_unref(gus);
                                        gus = NULL;
+                                       G_FREE(user_type)
                                        return -1;
                                }
 
@@ -886,20 +813,14 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                                        LOGE("[ERROR] Fail to remove engine info file");
                                }
 
-                               free(home_dir);
-                               home_dir = NULL;
-
-                               free(g_dir_engine_info);
-                               g_dir_engine_info = NULL;
-
-                               g_free(user_type);
-
-                               LOGD("Finish release memory");
-                               iter = g_list_next(iter);
-                               LOGD("Finish next iter");
-                       } else {
-                               iter = g_list_next(iter);
+                               G_FREE(home_dir)
+                               G_FREE(g_dir_engine_info)
                        }
+                       G_FREE(user_type)
+
+                       LOGD("Finish release memory");
+                       iter = g_list_next(iter);
+                       LOGD("Finish next iter");
                }
 
                gum_user_service_list_free(users);
@@ -914,7 +835,7 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                        LOGE("[ERROR] Invalid uid");
                        g_object_unref(g_guser);
                        g_guser = NULL;
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                } else {
                        LOGD("TZ_USER_HOME: %s", tzplatform_mkstr(TZ_USER_HOME, "/"));
@@ -926,7 +847,7 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                        LOGE("[ERROR] Fail to allocate memory");
                        g_object_unref(g_guser);
                        g_guser = NULL;
-                       g_free(g_user_type);
+                       G_FREE(g_user_type)
                        return -1;
                }
 
@@ -940,12 +861,9 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                g_object_unref(g_guser);
                g_guser = NULL;
        }
-       g_free(g_user_type);
+       G_FREE(g_user_type)
 
-       if (NULL != g_dir_engine_info) {
-               free(g_dir_engine_info);
-               g_dir_engine_info = NULL;
-       }
+       FREE(g_dir_engine_info)
 
        LOGD("");
        return 0;