From 585a7f4a60e8120958fba8a0269b47ca212e41ea Mon Sep 17 00:00:00 2001 From: vjymisal0 Date: Sun, 13 Sep 2026 18:05:49 +0530 Subject: [PATCH] fix(core): avoid crash on connection deinit via sqlite3_close_v2 --- Sources/SQLite/Core/Connection.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sources/SQLite/Core/Connection.swift b/Sources/SQLite/Core/Connection.swift index 625523c7..b2f10bcc 100644 --- a/Sources/SQLite/Core/Connection.swift +++ b/Sources/SQLite/Core/Connection.swift @@ -164,7 +164,14 @@ public final class Connection { } deinit { - try? close() + guard let handle = _handle else { + return + } + // Note: sqlite3_close_v2 differs from sqlite3_close. While sqlite3_close fails with + // SQLITE_BUSY if unfinalized prepared statements exist, sqlite3_close_v2 marks + // the connection as a zombie and defers final cleanup until all statements are finalized, + // preventing crashes or resource leaks when Connection is deallocated. + sqlite3_close_v2(handle) } // MARK: -