From 8277acefbd62a5a4846a10d1d9b4f7daa36ee363 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 25 Jun 2019 12:46:58 +0200 Subject: [PATCH] Fix leak on sqlite3 open error sqlite3_open creates the database object even if the operation fails. --- ext/sqlite3/sqlite3.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 61b032e900..e3474e4acb 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -136,6 +136,7 @@ PHP_METHOD(sqlite3, open) rc = sqlite3_open_v2(fullpath, &(db_obj->db), flags, NULL); if (rc != SQLITE_OK) { + sqlite3_close(db_obj->db); zend_throw_exception_ex(zend_ce_exception, 0, "Unable to open database: %s", #ifdef HAVE_SQLITE3_ERRSTR db_obj->db ? sqlite3_errmsg(db_obj->db) : sqlite3_errstr(rc)); @@ -151,6 +152,7 @@ PHP_METHOD(sqlite3, open) #if SQLITE_HAS_CODEC if (encryption_key_len > 0) { if (sqlite3_key(db_obj->db, encryption_key, encryption_key_len) != SQLITE_OK) { + sqlite3_close(db_obj->db); zend_throw_exception_ex(zend_ce_exception, 0, "Unable to open database: %s", sqlite3_errmsg(db_obj->db)); return; } -- 2.40.0