From 99db1687554d3b0bd7d5671e9f19d397378bed44 Mon Sep 17 00:00:00 2001 From: Wonnam Jang Date: Wed, 28 Dec 2016 21:09:18 +0900 Subject: [PATCH] Add ref count for db init/deinit Change-Id: I4234b263278ef94db192d1142b8e12a9451b9416 Signed-off-by: Wonnam Jang (cherry picked from commit 45e9a90b27cbb347f2839bd645513687520186c3) --- common/vc_cmd_db.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/common/vc_cmd_db.c b/common/vc_cmd_db.c index 16ca81d..3a040a6 100644 --- a/common/vc_cmd_db.c +++ b/common/vc_cmd_db.c @@ -59,6 +59,7 @@ const char* vc_db_tag() static sqlite3* db_handle = NULL; char* path = NULL; int g_fpid = -1; +int g_ref_cnt = 0; static int __vc_db_transaction(const char* transaction) { @@ -1063,6 +1064,11 @@ int vc_db_initialize(void) { SLOG(LOG_INFO, vc_db_tag(), "DB initialization"); + if (0 < g_ref_cnt) { + g_ref_cnt++; + return VC_DB_ERROR_NONE; + } + path = (char*)calloc(256, sizeof(char)); if (NULL == path) { SLOG(LOG_ERROR, vc_db_tag(), "[ERROR] Fail to allocate memory"); @@ -1112,12 +1118,16 @@ int vc_db_initialize(void) SLOG(LOG_ERROR, vc_db_tag(), "sqlite3_exec returned %d: %s", ret, err_msg); } } - + g_ref_cnt++; return VC_DB_ERROR_NONE; } int vc_db_finalize(void) { + if (0 >= g_ref_cnt) return VC_DB_ERROR_INVALID_STATE; + if (0 != --g_ref_cnt) + return VC_DB_ERROR_NONE; + if (NULL != path) { free(path); path = NULL; -- 2.7.4