From: Nikita Popov Date: Tue, 25 Jun 2019 10:46:58 +0000 (+0200) Subject: Fix leak on sqlite3 open error X-Git-Tag: php-7.4.0alpha3~189 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8277acefbd62a5a4846a10d1d9b4f7daa36ee363;p=php Fix leak on sqlite3 open error sqlite3_open creates the database object even if the operation fails. --- 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; }