Fix a issue of static analysis
[platform/core/appfw/pkgmgr-info.git] / src / pkgmgrinfo_pkginfo.c
index 0272937..b5cac35 100644 (file)
@@ -242,19 +242,19 @@ static int _get_filtered_query(pkgmgrinfo_filter_x *filter,
        if (filter == NULL)
                return PMINFO_R_OK;
 
-       len += strlen(" WHERE 1=1 ");
        strncat(buf, " WHERE 1=1 ", MAX_QUERY_LEN - len - 1);
+       len += strlen(" WHERE 1=1 ");
        for (list = filter->list; list; list = list->next) {
                joined |= __get_filter_condition(list->data, uid, &condition,
                                bind_params);
                if (condition == NULL)
                        continue;
 
-               len += strlen(" AND ");
                strncat(buf, " AND ", MAX_QUERY_LEN - len - 1);
+               len += strlen(" AND ");
 
-               len += strlen(condition);
                strncat(buf, condition, sizeof(buf) - len - 1);
+               len += strlen(condition);
                free(condition);
                condition = NULL;
        }
@@ -376,7 +376,7 @@ static int _pkginfo_get_packages(uid_t uid, const char *locale,
        author_x *author = NULL;
        GList *bind_params = NULL;
        sqlite3 *db;
-       sqlite3_stmt *stmt;
+       sqlite3_stmt *stmt = NULL;
        pkgmgrinfo_filter_x *tmp_filter = NULL;
        bool is_check_storage = true;
 
@@ -570,7 +570,8 @@ catch:
 
        g_list_free_full(bind_params, free);
        sqlite3_close_v2(db);
-       sqlite3_finalize(stmt);
+       if (stmt)
+               sqlite3_finalize(stmt);
 
        return ret;
 }