From 565cdfa16bd721602181eb22cd680bace54215b5 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Thu, 16 May 2024 08:37:12 +0900 Subject: [PATCH] Release from caller Change-Id: Ib0ea0313c02189a1fbebff0e9167070c784d3ccc Signed-off-by: Minje Ahn --- lib/include/media-util-db.h | 2 +- lib/media-util-db.c | 14 ++++---------- packaging/media-server.spec | 2 +- src/common/media-common-db-svc.c | 3 +++ src/mediadb-update.c | 2 ++ 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/include/media-util-db.h b/lib/include/media-util-db.h index a5af02a..0ba6352 100644 --- a/lib/include/media-util-db.h +++ b/lib/include/media-util-db.h @@ -32,7 +32,7 @@ void media_db_disconnect(sqlite3 *handle); int media_db_request_update_db(const char *query_str, uid_t uid); int media_db_update_db_direct(const char *query_str, uid_t uid); int media_db_check_integrity(sqlite3 *handle); -int media_db_get_result(sqlite3 *handle, char *sql_str, sqlite3_stmt **stmt); +int media_db_get_result(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt); /** * @} diff --git a/lib/media-util-db.c b/lib/media-util-db.c index 22204f3..cecba1d 100644 --- a/lib/media-util-db.c +++ b/lib/media-util-db.c @@ -334,22 +334,16 @@ int media_db_update_db_direct(const char *query_str, uid_t uid) return ret; } -int media_db_get_result(sqlite3 *handle, char *sql_str, sqlite3_stmt **stmt) +int media_db_get_result(sqlite3 *handle, const char *sql_str, sqlite3_stmt **stmt) { - int err = -1; + int err = SQLITE_OK; - MSAPI_RETVM_IF(sql_str == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "invalid query"); - if (handle == NULL) { - MSAPI_DBG_ERR("handle is NULL"); - sqlite3_free(sql_str); - return MS_MEDIA_ERR_INVALID_PARAMETER; - } + MSAPI_RETVM_IF(!sql_str, MS_MEDIA_ERR_INVALID_PARAMETER, "invalid query"); + MSAPI_RETVM_IF(!handle, MS_MEDIA_ERR_INVALID_PARAMETER, "handle is null"); MSAPI_DBG_SLOG("[SQL query] : %s", sql_str); err = sqlite3_prepare_v2(handle, sql_str, -1, stmt, NULL); - sqlite3_free(sql_str); - if (err != SQLITE_OK) { MSAPI_DBG_ERR("prepare error %d[%s]", err, sqlite3_errmsg(handle)); if (err == SQLITE_CORRUPT) diff --git a/packaging/media-server.spec b/packaging/media-server.spec index 214cf72..c3e3da8 100644 --- a/packaging/media-server.spec +++ b/packaging/media-server.spec @@ -1,6 +1,6 @@ Name: media-server Summary: A server for media content management -Version: 0.6.4 +Version: 0.6.5 Release: 0 Group: Multimedia/Service License: Apache-2.0 diff --git a/src/common/media-common-db-svc.c b/src/common/media-common-db-svc.c index 653328f..568e9b8 100644 --- a/src/common/media-common-db-svc.c +++ b/src/common/media-common-db-svc.c @@ -213,6 +213,7 @@ static int __ms_check_item_exist(sqlite3 *handle, const char *storage_id, const #endif ret = media_db_get_result(handle, sql, &sql_stmt); + sqlite3_free(sql); MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Error when media_db_get_result. err = [%d]", ret); if (sqlite3_step(sql_stmt) != SQLITE_ROW) { @@ -307,6 +308,7 @@ int ms_delete_invalid_items(sqlite3 *handle, const char *storage_id, uid_t uid) MS_DBG_SLOG("[SQL query] : %s", sql); ret = media_db_get_result(handle, sql, &sql_stmt); + sqlite3_free(sql); if (ret != MS_MEDIA_ERR_NONE) { MS_DBG_ERR("Query failed. err[%d]", ret); g_ptr_array_free(thumb_list, TRUE); @@ -529,6 +531,7 @@ int ms_get_folder_id(sqlite3 *handle, const char *storage_id, const char *path, sql = sqlite3_mprintf("SELECT folder_id FROM folder WHERE folder_path=%Q", path); #endif ret = media_db_get_result(handle, sql, &sql_stmt); + sqlite3_free(sql); MS_DBG_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret); if (sqlite3_step(sql_stmt) == SQLITE_ROW) { diff --git a/src/mediadb-update.c b/src/mediadb-update.c index 81fb4b7..9fc59a2 100644 --- a/src/mediadb-update.c +++ b/src/mediadb-update.c @@ -107,8 +107,10 @@ static char * __get_storage_id(const char *path, uid_t uid) char *q = sqlite3_mprintf("SELECT storage_id FROM storage WHERE instr(%Q, storage_path)", path); if (media_db_get_result(handle, q, &stmt) < 0) { printf("Failed to get storage id\n"); + sqlite3_free(q); return NULL; } + sqlite3_free(q); if (sqlite3_step(stmt) == SQLITE_ROW) storage_id = g_strdup((const char *)sqlite3_column_text(stmt, 0)); -- 2.7.4