From 56992a61025d8c50ec59e57b550d6f3215857164 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Mon, 17 Apr 2017 20:13:59 +0900 Subject: [PATCH] Fix a bug regarding category data Because strtok() modifies the original data, the second query for global db is affected. this causes unexpected result of multiple categroy filtering. Change-Id: I72595fe9d254c36bbb433ff035aa07d10fd34177 Signed-off-by: jongmyeongko --- src/pkgmgrinfo_private.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pkgmgrinfo_private.c b/src/pkgmgrinfo_private.c index b415acb..4fa7551 100644 --- a/src/pkgmgrinfo_private.c +++ b/src/pkgmgrinfo_private.c @@ -238,6 +238,7 @@ int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **p pkgmgrinfo_node_x *node = (pkgmgrinfo_node_x *)data; char buf[MAX_QUERY_LEN] = {'\0'}; int flag = 0; + char *value; char *ptr = NULL; char *saveptr = NULL; size_t len = 0; @@ -329,9 +330,16 @@ int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **p break; case E_PMINFO_APPINFO_PROP_APP_CATEGORY: snprintf(buf, sizeof(buf), "package_app_app_category.category IN ("); - ptr = strtok_r(node->value, ",", &saveptr); - if (ptr == NULL) + value = strdup(node->value); + if (value == NULL) { + _LOGE("out of memeory"); return 0; + } + ptr = strtok_r(value, ",", &saveptr); + if (ptr == NULL) { + free(value); + return 0; + } strncat(buf, "?", MAX_QUERY_LEN - len - 1); len += strlen("?"); *params = g_list_append(*params, strdup(ptr)); @@ -344,6 +352,7 @@ int __get_filter_condition(gpointer data, uid_t uid, char **condition, GList **p len += strlen("?"); *condition = strdup(buf); flag = E_PMINFO_APPINFO_JOIN_CATEGORY; + free(value); return flag; case E_PMINFO_APPINFO_PROP_APP_NODISPLAY: -- 2.7.4