Set a default value for max text size
[platform/core/uifw/tts.git] / engine-parser / src / tts-engine-parser.c
index 68786dc..237aa79 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <fcntl.h>
 #include <tzplatform_config.h>
 #include <systemd/sd-login.h>
 
@@ -51,6 +52,7 @@
 #define TTS_TAG_ENGINE_VOICE_TYPE              "type"
 #define TTS_TAG_ENGINE_PITCH_SUPPORT           "pitch-support"
 #define TTS_TAG_ENGINE_CREDENTIAL              "credential"
+#define TTS_TAG_ENGINE_TEXT_SIZE               "text-size"
 
 #define TTS_CONFIG_BASE                tzplatform_mkpath(TZ_USER_HOME, "share/.voice")
 #define TTS_HOME               tzplatform_mkpath(TZ_USER_HOME, "share/.voice/tts")
 #define TTS_METADATA_LANGUAGE                  "http://tizen.org/metadata/tts-engine/language"
 #define TTS_METADATA_CREDENTIAL_REQUIRED       "http://tizen.org/metadata/tts-engine/credential-required"
 #define TTS_METADATA_SETTING           "http://tizen.org/metadata/tts-engine/setting"
+#define TTS_METADATA_TEXT_SIZE         "http://tizen.org/metadata/tts-engine/text-size"
+#define TTS_METADATA_PITCH_SUPPORT     "http://tizen.org/metadata/tts-engine/pitch-support"
+
+#define TTS_MAX_TEXT_SIZE      "2000"
+
+/* 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;
@@ -84,21 +94,22 @@ char *g_dir_home = NULL;
 char *g_dir_engine_base = NULL;
 char *g_dir_engine_info = NULL;
 
+
 static int __create_engine_info_xml(const char *pkgid)
 {
-       LOGD("=== Create engine info doc");
+       LOGD("@@@ Create engine info doc");
        g_doc = xmlNewDoc((xmlChar*)"1.0");
        if (NULL == g_doc) {
                LOGE("[ERROR] Fail to new doc");
                return -1;
        }
-       LOGD("===");
+       LOGD("@@@");
        return 0;
 }
 
 static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t gid)
 {
-       LOGD("=== Save engine info doc");
+       LOGD("@@@ Save engine info doc");
        char *dir_config_base = NULL;
        char *dir_home = NULL;
        char *dir_engine_base = NULL;
@@ -139,22 +150,11 @@ 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;
        }
 
@@ -162,92 +162,97 @@ static int __save_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid, gid_t
 
 
        /* Make directories */
-       if (0 != access(dir_config_base, F_OK)) {
+       int fd = -1;
+//     if (0 != access(dir_config_base, F_OK)) {
+       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", dir_config_base);
-                       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;
+                       LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_config_base, errno);
+                       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);
                        if (0 != chown(dir_config_base, tmp_uid, tmp_gid)) {
-                               LOGD("[ERROR] Fail to change user and group");
+                               LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
                        } else {
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
+       } else {
+               close(fd);
        }
 
-       if (0 != access(dir_home, F_OK)) {
+//     if (0 != access(dir_home, F_OK)) {
+       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", dir_home);
-                       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;
+                       LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_home, errno);
+                       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);
                        if (0 != chown(dir_home, tmp_uid, tmp_gid)) {
-                               LOGD("[ERROR] Fail to change user and group");
+                               LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
                        } else {
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
+       } else {
+               close(fd);
        }
 
-       if (0 != access(dir_engine_base, F_OK)) {
+//     if (0 != access(dir_engine_base, F_OK)) {
+       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", dir_engine_base);
-                       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;
+                       LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_engine_base, errno);
+                       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);
                        if (0 != chown(dir_engine_base, tmp_uid, tmp_gid)) {
-                               LOGD("[ERROR] Fail to change user and group");
+                               LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
                        } else {
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
+       } else {
+               close(fd);
        }
 
-       if (0 != access(dir_engine_info, F_OK)) {
+//     if (0 != access(dir_engine_info, F_OK)) {
+       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", dir_engine_info);
-                       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;
+                       LOGE("[ERROR] Fail to make directory : %s, errno : %d", dir_engine_info, errno);
+                       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);
                        if (0 != chown(dir_engine_info, tmp_uid, tmp_gid)) {
-                               LOGD("[ERROR] Fail to change user and group");
+                               LOGD("[ERROR] Fail to change user and group, errno : %d", errno);
                        } else {
                                LOGD("[DEBUG] Success to change user and group");
                        }
                }
+       } else {
+               close(fd);
        }
 
 
@@ -263,22 +268,18 @@ 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("===");
+       LOGD("@@@");
        return 0;
 }
 
 static int __remove_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
 {
-       LOGD("=== Remove engine info doc");
+       LOGD("@@@ Remove engine info doc");
 
        char *dir_engine_info = NULL;
 
@@ -317,19 +318,22 @@ static int __remove_engine_info_xml(const char *pkgid, gchar *ut, uid_t uid)
                }
        }
 
-       free(dir_engine_info);
-       dir_engine_info = NULL;
+       FREE(dir_engine_info)
 
-       LOGD("===");
+       LOGD("@@@");
        return 0;
 }
 
 static void __insert_language_from_metadata(xmlNodePtr root, const char *language)
 {
-       LOGD("==== Insert language");
+       LOGD("@@@ Insert language");
        char* voice = NULL;
        char* lang = NULL;
        char* type = NULL;
+       if (NULL == root || NULL == language) {
+               LOGE("Invalid parameter, root(%p), language(%s)", root, language);
+               return;
+       }
 
        char *tmp_lang = NULL;
        char *tmp_free = NULL;
@@ -358,8 +362,7 @@ static void __insert_language_from_metadata(xmlNodePtr root, const char *languag
        }
        xmlAddChild(root, voices_node);
 
-       free(tmp_free);
-       tmp_free = NULL;
+       FREE(tmp_free)
 }
 
 static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *list)
@@ -367,6 +370,8 @@ static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *l
        GList *iter = NULL;
        metadata *md = NULL;
 
+       bool isTextsize = false;
+
        __create_engine_info_xml(pkgid);
 
        xmlNodePtr root = NULL;
@@ -405,6 +410,15 @@ static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *l
                                cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_NAME);
                                xmlNodeSetContent(cur, (const xmlChar*)md->value);
                                xmlAddChild(root, cur);
+                       } else if (!strcmp(md->key, TTS_METADATA_TEXT_SIZE)) {
+                               cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_TEXT_SIZE);
+                               xmlNodeSetContent(cur, (const xmlChar*)md->value);
+                               xmlAddChild(root, cur);
+                               isTextsize = true;
+                       } else if (!strcmp(md->key, TTS_METADATA_PITCH_SUPPORT)) {
+                               cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_PITCH_SUPPORT);
+                               xmlNodeSetContent(cur, (const xmlChar*)md->value);
+                               xmlAddChild(root, cur);
                        } else {
                                LOGW("[WARNING] Unknown metadata type");
                        }
@@ -412,6 +426,13 @@ static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *l
                iter = g_list_next(iter);
        }
 
+       if (false == isTextsize) {
+               cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_TEXT_SIZE);
+               xmlNodeSetContent(cur, (const xmlChar*)TTS_MAX_TEXT_SIZE);
+               xmlAddChild(root, cur);
+               LOGD("[DEBUG] Max text size is set as %s.", TTS_MAX_TEXT_SIZE);
+       }
+
        cur = xmlNewNode(NULL, (const xmlChar*)TTS_TAG_ENGINE_ID);
        xmlNodeSetContent(cur, (const xmlChar*)pkgid);
        xmlAddChild(root, cur);
@@ -467,7 +488,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;
        }
 
@@ -476,14 +497,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;
                }
 
@@ -495,31 +516,20 @@ 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;
                }
 
@@ -540,7 +550,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;
                }
 
@@ -550,11 +560,11 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList *
                g_strfreev(query);
 
                if (!users) {
-                       LOGE("Failed to get gum user list");
+                       LOGD("NO users");
                        g_object_unref(gus);
                        gus = NULL;
-                       g_free(g_user_type);
-                       return -1;
+                       G_FREE(g_user_type)
+                       return 0;
                }
 
                /* Make new user list */
@@ -563,16 +573,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;
@@ -589,25 +598,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);
@@ -621,29 +620,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);
@@ -658,7 +644,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, "/"));
@@ -669,7 +655,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;
                }
 
@@ -678,7 +664,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;
                }
 
@@ -689,26 +675,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;
                }
 
@@ -719,7 +693,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;
                }
        }
@@ -729,24 +703,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;
 }
@@ -770,7 +732,10 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
        uid_t globalapp_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
        if (globalapp_uid == g_uid) {
                g_user_type = g_strdup("admin");
+               LOGD("[DEBUG] g_user_type: %s (%d)", g_user_type, globalapp_uid);
        } else {
+               LOGD("[DEBUG] globalapp_uid(%d)", globalapp_uid);
+
                g_guser = gum_user_get_sync(g_uid, FALSE);
                if (NULL == g_guser) {
                        LOGE("[ERROR] g_guser is NULL");
@@ -779,6 +744,8 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
 
                g_object_get(G_OBJECT(g_guser), "usertype", &g_ut, NULL);
                g_user_type = g_strdup(gum_user_type_to_string(g_ut));
+
+               LOGD("[DEBUG] g_guser(%s), g_ut(%s), g_user_type(%s)", g_guser, g_ut, g_user_type);
        }
 
        if (NULL == g_user_type) {
@@ -795,7 +762,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;
        }
 
@@ -807,7 +774,7 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                g_dir_engine_info = strdup(TTS_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;
                }
 
@@ -834,7 +801,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;
                }
 
@@ -844,11 +811,11 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList
                g_strfreev(query);
 
                if (!users) {
-                       LOGE("Failed to get gum user list");
+                       LOGD("NO users");
                        g_object_unref(gus);
                        gus = NULL;
-                       g_free(g_user_type);
-                       return -1;
+                       G_FREE(g_user_type)
+                       return 0;
                }
 
                /* Make new user list */
@@ -857,15 +824,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;
@@ -875,8 +840,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;
                                }
 
@@ -893,20 +860,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)
+                               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);
@@ -921,7 +882,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, "/"));
@@ -933,7 +894,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;
                }
 
@@ -947,12 +908,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;