]> granicus.if.org Git - php/commitdiff
Fix leak on sqlite3 open error
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 25 Jun 2019 10:46:58 +0000 (12:46 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 25 Jun 2019 12:28:58 +0000 (14:28 +0200)
sqlite3_open creates the database object even if the operation
fails.

ext/sqlite3/sqlite3.c

index 61b032e900db56f6005fafdfeb2d87edbfd06222..e3474e4acba22bcc998eea5b62d66d1870b4e7da 100644 (file)
@@ -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;
                }