mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
wallet: Call db_stmt_free from the db_stmt destructor automatically
This is much more in line with the rest of our memory management. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
093f5bfbec
commit
e65e4fcf4b
20
wallet/db.c
20
wallet/db.c
@@ -554,6 +554,13 @@ sqlite3_stmt *db_select_prepare_(const char *location, struct db *db, const char
|
|||||||
return stmt;
|
return stmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void db_stmt_free(struct db_stmt *stmt)
|
||||||
|
{
|
||||||
|
if (stmt->inner_stmt)
|
||||||
|
stmt->db->config->stmt_free_fn(stmt);
|
||||||
|
assert(stmt->inner_stmt == NULL);
|
||||||
|
}
|
||||||
|
|
||||||
struct db_stmt *db_prepare_v2_(const char *location, struct db *db,
|
struct db_stmt *db_prepare_v2_(const char *location, struct db *db,
|
||||||
const char *query_id)
|
const char *query_id)
|
||||||
{
|
{
|
||||||
@@ -586,12 +593,11 @@ struct db_stmt *db_prepare_v2_(const char *location, struct db *db,
|
|||||||
stmt->location = location;
|
stmt->location = location;
|
||||||
stmt->error = NULL;
|
stmt->error = NULL;
|
||||||
stmt->db = db;
|
stmt->db = db;
|
||||||
return stmt;
|
stmt->inner_stmt = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
void db_stmt_free(struct db_stmt *stmt)
|
tal_add_destructor(stmt, db_stmt_free);
|
||||||
{
|
|
||||||
stmt->db->config->stmt_free_fn(stmt);
|
return stmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define db_prepare_v2(db,query) \
|
#define db_prepare_v2(db,query) \
|
||||||
@@ -882,7 +888,7 @@ static void db_migrate(struct lightningd *ld, struct db *db, struct log *log)
|
|||||||
struct db_stmt *stmt =
|
struct db_stmt *stmt =
|
||||||
db_prepare_v2(db, dbmigrations[current].sql);
|
db_prepare_v2(db, dbmigrations[current].sql);
|
||||||
db_exec_prepared_v2(stmt);
|
db_exec_prepared_v2(stmt);
|
||||||
db_stmt_free(stmt);
|
tal_free(stmt);
|
||||||
}
|
}
|
||||||
if (dbmigrations[current].func)
|
if (dbmigrations[current].func)
|
||||||
dbmigrations[current].func(ld, db);
|
dbmigrations[current].func(ld, db);
|
||||||
@@ -1281,7 +1287,7 @@ void migrate_pr2342_feerate_per_channel(struct lightningd *ld, struct db *db)
|
|||||||
db_bind_int(stmt, 1, ld->config.fee_per_satoshi);
|
db_bind_int(stmt, 1, ld->config.fee_per_satoshi);
|
||||||
|
|
||||||
db_exec_prepared_v2(stmt);
|
db_exec_prepared_v2(stmt);
|
||||||
db_stmt_free(stmt);
|
tal_free(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sqlite3_bind_timeabs(sqlite3_stmt *stmt, int col, struct timeabs t)
|
void sqlite3_bind_timeabs(sqlite3_stmt *stmt, int col, struct timeabs t)
|
||||||
|
|||||||
@@ -249,7 +249,6 @@ void db_bind_blob(struct db_stmt *stmt, int pos, u8 *val, size_t len);
|
|||||||
void db_bind_text(struct db_stmt *stmt, int pos, const char *val);
|
void db_bind_text(struct db_stmt *stmt, int pos, const char *val);
|
||||||
bool db_exec_prepared_v2(struct db_stmt *stmt TAKES);
|
bool db_exec_prepared_v2(struct db_stmt *stmt TAKES);
|
||||||
|
|
||||||
void db_stmt_free(struct db_stmt *stmt);
|
|
||||||
|
|
||||||
struct db_stmt *db_prepare_v2_(const char *location, struct db *db,
|
struct db_stmt *db_prepare_v2_(const char *location, struct db *db,
|
||||||
const char *query_id);
|
const char *query_id);
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ static void db_sqlite3_stmt_free(struct db_stmt *stmt)
|
|||||||
{
|
{
|
||||||
if (stmt->inner_stmt)
|
if (stmt->inner_stmt)
|
||||||
sqlite3_finalize(stmt->inner_stmt);
|
sqlite3_finalize(stmt->inner_stmt);
|
||||||
tal_free(stmt);
|
stmt->inner_stmt = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct db_config db_sqlite3_config = {
|
struct db_config db_sqlite3_config = {
|
||||||
|
|||||||
Reference in New Issue
Block a user