Fix memory leak
[platform/core/appfw/librua.git] / src / rua_util.h
index 13efffe..ce77c31 100644 (file)
 
 #include <sqlite3.h>
 
+#define __BIND_TEXT(db, stmt, i, text)                                         \
+do {                                                                           \
+       if (sqlite3_bind_text(stmt, i, text, -1, SQLITE_STATIC) != SQLITE_OK) {\
+               LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db));       \
+               sqlite3_finalize(stmt);                                        \
+               return -1;                                                     \
+       }                                                                      \
+} while (0)
+
+#define __BIND_INT(db, stmt, i, int)                                           \
+do {                                                                           \
+       if (sqlite3_bind_int(stmt, i, int) != SQLITE_OK) {                     \
+               LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db));       \
+               sqlite3_finalize(stmt);                                        \
+               return -1;                                                     \
+       }                                                                      \
+} while (0)
+
+#define __BIND_DOUBLE(db, stmt, i, double)                                     \
+do {                                                                           \
+       if (sqlite3_bind_double(stmt, i, double) != SQLITE_OK) {               \
+               LOGE("bind error(index %d): %s", i, sqlite3_errmsg(db));       \
+               sqlite3_finalize(stmt);                                        \
+               return -1;                                                     \
+       }                                                                      \
+} while (0)
+
 char *_rua_util_get_db_path(uid_t uid, char *db_name);
 int _rua_util_open_db(sqlite3 **db, int flags, uid_t uid, char *db_name);
 int _rua_util_check_uid(uid_t target_uid);