From c55f445afa35423bd57dc57a0787a72a3c7a4f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=9Awi=C4=85tkowski?= Date: Tue, 14 Jul 2026 12:32:03 +0200 Subject: [PATCH] Close connection after error on open This is a behaviour that docs describe as correct: > Whether or not an error occurs when it is opened, resources associated > with the database connection handle should be released by passing it > to sqlite3_close() when it is no longer required. https://www.sqlite.org/c3ref/open.html --- c_src/sqlite3_nif.c | 1 + 1 file changed, 1 insertion(+) diff --git a/c_src/sqlite3_nif.c b/c_src/sqlite3_nif.c index 715b3926..7338c83c 100644 --- a/c_src/sqlite3_nif.c +++ b/c_src/sqlite3_nif.c @@ -461,6 +461,7 @@ exqlite_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) rc = sqlite3_open_v2((char*)bin.data, &db, flags, NULL); if (rc != SQLITE_OK) { + sqlite3_close_v2(db); return make_error_tuple(env, am_database_open_failed); }