Skip to content

Commit 430a21f

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: sqlite3: Fix leak when trying to close db if blob stream is still open
2 parents 8fb6827 + d2f92b3 commit 430a21f

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎ext/sqlite3/sqlite3.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2314,7 +2314,9 @@ static void php_sqlite3_object_free_storage(zend_object *object) /* {{{ */
23142314
}
23152315

23162316
if (intern->initialised && intern->db) {
2317-
sqlite3_close(intern->db);
2317+
/* Use sqlite3_close_v2() because the object may be destroyed while resources depending on the connection are still alive,
2318+
* e.g. a blob stream created by SQLite3::openBlob(). */
2319+
sqlite3_close_v2(intern->db);
23182320
intern->initialised = false;
23192321
}
23202322

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Destroying the SQLite3 object while a blob stream is still open must not leak the connection
3+
--EXTENSIONS--
4+
sqlite3
5+
--FILE--
6+
<?php
7+
8+
$db = new SQLite3(':memory:');
9+
$db->exec('CREATE TABLE test (data BLOB)');
10+
$db->exec("INSERT INTO test (data) VALUES (x'34323432')");
11+
12+
$stream = $db->openBlob('test', 'data', 1);
13+
var_dump($db->close());
14+
unset($db);
15+
var_dump(fread($stream, 4));
16+
fclose($stream);
17+
18+
?>
19+
--EXPECTF--
20+
Warning: SQLite3::close(): Unable to close database: %s in %s on line %d
21+
bool(false)
22+
string(4) "4242"

0 commit comments

Comments
 (0)