From 285150bb7a3dddab309cc2f8596481dabe09eaa6 Mon Sep 17 00:00:00 2001 From: Amos Kariuki Date: Wed, 21 May 2025 18:39:28 -0700 Subject: [PATCH] Fix crash in static database destruction due to unsafe lambda capture Crash would occur when a static object holding a shared_ptr object was destroyed due to capturing local variables by value using [=] in the shared_ptr's custom deleter lambda. The deleter doesn't use any captured variables so use an empty clause instead. --- hdr/sqlite_modern_cpp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hdr/sqlite_modern_cpp.h b/hdr/sqlite_modern_cpp.h index 09665d38..ae840deb 100644 --- a/hdr/sqlite_modern_cpp.h +++ b/hdr/sqlite_modern_cpp.h @@ -386,7 +386,7 @@ namespace sqlite { database(const std::string &db_name, const sqlite_config &config = {}): _db(nullptr) { sqlite3* tmp = nullptr; auto ret = sqlite3_open_v2(db_name.data(), &tmp, static_cast(config.flags), config.zVfs); - _db = std::shared_ptr(tmp, [=](sqlite3* ptr) { sqlite3_close_v2(ptr); }); // this will close the connection eventually when no longer needed. + _db = std::shared_ptr(tmp, [](sqlite3* ptr) { sqlite3_close_v2(ptr); }); // this will close the connection eventually when no longer needed. if(ret != SQLITE_OK) errors::throw_sqlite_error(_db ? sqlite3_extended_errcode(_db.get()) : ret, {}, sqlite3_errmsg(_db.get())); sqlite3_extended_result_codes(_db.get(), true); if(config.encoding == Encoding::UTF16)