Skip to content

Commit 353f214

Browse files
committed
Fix cycle leak in sqlite3 setAuthorizer()
Closes GH-17903.
1 parent 2c251f9 commit 353f214

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ PHP NEWS
4848
- PDO_SQLite:
4949
. Fixed GH-17837 ()::getColumnMeta() on unexecuted statement segfaults).
5050
(cmb)
51+
. Fix cycle leak in sqlite3 setAuthorizer(). (nielsdos)
5152

5253
- Phar:
5354
. Fixed bug GH-17808: PharFileInfo refcount bug. (nielsdos)

ext/sqlite3/sqlite3.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2256,14 +2256,16 @@ static HashTable *php_sqlite3_get_gc(zend_object *object, zval **table, int *n)
22562256
{
22572257
php_sqlite3_db_object *intern = php_sqlite3_db_from_obj(object);
22582258

2259-
if (intern->funcs == NULL && intern->collations == NULL) {
2259+
if (intern->funcs == NULL && intern->collations == NULL && !ZEND_FCC_INITIALIZED(intern->authorizer_fcc)) {
22602260
/* Fast path without allocations */
22612261
*table = NULL;
22622262
*n = 0;
22632263
return zend_std_get_gc(object, table, n);
22642264
} else {
22652265
zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create();
22662266

2267+
php_sqlite3_gc_buffer_add_fcc(gc_buffer, &intern->authorizer_fcc);
2268+
22672269
php_sqlite3_func *func = intern->funcs;
22682270
while (func != NULL) {
22692271
php_sqlite3_gc_buffer_add_fcc(gc_buffer, &func->func);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
setAuthorizer() cycle leak
3+
--EXTENSIONS--
4+
sqlite3
5+
--FILE--
6+
<?php
7+
class Foo extends Sqlite3 {
8+
public function __construct() {
9+
parent::__construct(":memory:");
10+
$this->setAuthorizer([$this, "foo"]);
11+
}
12+
13+
public function foo() {}
14+
}
15+
16+
$test = new Foo;
17+
18+
echo "Done\n";
19+
?>
20+
--EXPECT--
21+
Done

0 commit comments

Comments
 (0)