Skip to content

Commit 8277ace

Browse files
committed
Fix leak on sqlite3 open error
sqlite3_open creates the database object even if the operation fails.
1 parent 6fcae63 commit 8277ace

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

ext/sqlite3/sqlite3.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ PHP_METHOD(sqlite3, open)
136136

137137
rc = sqlite3_open_v2(fullpath, &(db_obj->db), flags, NULL);
138138
if (rc != SQLITE_OK) {
139+
sqlite3_close(db_obj->db);
139140
zend_throw_exception_ex(zend_ce_exception, 0, "Unable to open database: %s",
140141
#ifdef HAVE_SQLITE3_ERRSTR
141142
db_obj->db ? sqlite3_errmsg(db_obj->db) : sqlite3_errstr(rc));
@@ -151,6 +152,7 @@ PHP_METHOD(sqlite3, open)
151152
#if SQLITE_HAS_CODEC
152153
if (encryption_key_len > 0) {
153154
if (sqlite3_key(db_obj->db, encryption_key, encryption_key_len) != SQLITE_OK) {
155+
sqlite3_close(db_obj->db);
154156
zend_throw_exception_ex(zend_ce_exception, 0, "Unable to open database: %s", sqlite3_errmsg(db_obj->db));
155157
return;
156158
}

0 commit comments

Comments
 (0)