Skip to content

Commit 09b3423

Browse files
committed
fix: resolve memory leaks in arkilian-dlq and ensure database handles are closed in hydration logic
1 parent 80934a1 commit 09b3423

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/hydration.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,8 @@ int arkilian_hydrate(const char *db_path,
867867
sqlite3 *ldb = NULL;
868868
if (sqlite3_open_v2(db_path, &ldb, SQLITE_OPEN_READONLY, NULL) == SQLITE_OK) {
869869
pre_local_lsn = read_last_applied_lsn(ldb);
870-
sqlite3_close(ldb);
871870
}
871+
sqlite3_close(ldb);
872872
if (pre_local_lsn > plan.baseline_lsn) {
873873
fprintf(stderr,
874874
"arkilian: hydration refused — local DB is at LSN %lld but the "
@@ -908,8 +908,8 @@ int arkilian_hydrate(const char *db_path,
908908
goto hydrate_done;
909909
}
910910
sqlite3_exec(ldb, "ROLLBACK;", NULL, NULL, NULL);
911-
sqlite3_close(ldb);
912911
}
912+
sqlite3_close(ldb);
913913
}
914914

915915
// ── Phase 1: Download baseline snapshot ──

tools/arkilian-dlq.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ static int cmd_replay(const char *path, long long only_id, int dry_run) {
170170
}
171171
if (rc != SQLITE_OK) {
172172
fprintf(stderr, "replay prepare failed: %s\n", sqlite3_errmsg(db));
173+
sqlite3_free(replay_sql);
174+
sqlite3_free(cleanup_sql);
173175
sqlite3_close(db);
174176
return 1;
175177
}
@@ -187,6 +189,9 @@ static int cmd_replay(const char *path, long long only_id, int dry_run) {
187189
if (rc == SQLITE_OK && sqlite3_step(st) == SQLITE_DONE) removed = sqlite3_changes(db);
188190
sqlite3_finalize(st);
189191

192+
sqlite3_free(replay_sql);
193+
sqlite3_free(cleanup_sql);
194+
190195
printf("replayed %d row(s) to _pending_backup, removed %d from _dead_backup\n",
191196
replayed, removed);
192197
sqlite3_close(db);

0 commit comments

Comments
 (0)