#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;
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);
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);
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);
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);
LOGD("[DEBUG] Success to change user and group");
}
}
+ } else {
+ close(fd);
}
char path[256] = {'\0',};
}
}
- 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("===");
}
}
- if (NULL != dir_engine_info) {
- free(dir_engine_info);
- dir_engine_info = NULL;
- }
+ FREE(dir_engine_info)
LOGD("===");
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;
}
xmlAddChild(root, languages_node);
- free(tmp_free);
+ FREE(tmp_free)
}
static int __write_metadata_inxml(const char *pkgid, const char *appid, GList *list)
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;
}
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;
}
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;
}
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;
}
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;
}
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;
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);
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);
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, "/"));
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;
}
xmlFreeDoc(g_doc);
g_object_unref(g_guser);
g_guser = NULL;
- g_free(g_user_type);
+ G_FREE(g_user_type)
return -1;
}
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;
}
g_object_unref(g_guser);
g_guser = NULL;
}
- g_free(g_user_type);
+ G_FREE(g_user_type)
return -1;
}
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
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;
}
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);
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, "/"));
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;
}
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;