Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ PHP NEWS
(Ilia Alshanetsky)
. Fixed a duplicate warning when ATTR_STATEMENT_CLASS is rejected on a
persistent connection. (Ilia Alshanetsky)
. Fixed crash when the garbage collector freed SQLite user functions,
aggregates, or collations of a persistent connection shared by several
PDO objects. (Ilia Alshanetsky)

- Phpdbg:
. Fix wrong command names. (ndossche, Weilin Du)
Expand Down
3 changes: 2 additions & 1 deletion ext/pdo/pdo_dbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,8 @@ static HashTable *dbh_get_gc(zend_object *object, zval **gc_data, int *gc_count)
pdo_dbh_t *dbh = php_pdo_dbh_fetch_inner(object);
zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create();
zend_get_gc_buffer_add_zval(gc_buffer, &dbh->def_stmt_ctor_args);
if (dbh->methods && dbh->methods->get_gc) {
if (dbh->methods && dbh->methods->get_gc
&& (!dbh->is_persistent || dbh->refcount <= 2)) {
dbh->methods->get_gc(dbh, gc_buffer);
}
zend_get_gc_buffer_use(gc_buffer, gc_data, gc_count);
Expand Down
30 changes: 30 additions & 0 deletions ext/pdo_sqlite/tests/gc_persistent_shared.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
GC must not free callbacks of a persistent connection shared by several PDO objects
--EXTENSIONS--
pdo_sqlite
--FILE--
<?php
class Repo {
public Pdo\Sqlite $pdo;

public function __construct(public string $name) {
$this->pdo = Pdo\Sqlite::connect('sqlite::memory:', null, null, [PDO::ATTR_PERSISTENT => true]);
$this->pdo->createFunction("udf_$name", [$this, 'udf'], 1);
}

public function udf($x) {
return $this->name . $x;
}
}

$repos = [new Repo('one'), new Repo('two')];
echo "collected: "; var_dump(gc_collect_cycles());
echo "udf_one: "; var_dump($repos[0]->pdo->query("SELECT udf_one('!')")->fetchColumn());
echo "udf_two: "; var_dump($repos[1]->pdo->query("SELECT udf_two('?')")->fetchColumn());

unset($repos[0]->pdo, $repos[1]->pdo);
?>
--EXPECT--
collected: int(0)
udf_one: string(4) "one!"
udf_two: string(4) "two?"
Loading