Skip to content

Commit 6a4b0c9

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix memory leaks in pdo_sqlite callback registration Fix cycle leak in sqlite3 setAuthorizer()
2 parents 6746634 + 635fe26 commit 6a4b0c9

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

ext/pdo_sqlite/sqlite_driver.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ void pdo_sqlite_create_function_internal(INTERNAL_FUNCTION_PARAMETERS)
512512
ZEND_PARSE_PARAMETERS_END_EX(goto error;);
513513

514514
dbh = Z_PDO_DBH_P(ZEND_THIS);
515-
PDO_CONSTRUCT_CHECK;
515+
PDO_CONSTRUCT_CHECK_WITH_CLEANUP(error);
516516

517517
H = (pdo_sqlite_db_handle *)dbh->driver_data;
518518

@@ -569,7 +569,7 @@ void pdo_sqlite_create_aggregate_internal(INTERNAL_FUNCTION_PARAMETERS)
569569
ZEND_PARSE_PARAMETERS_END_EX(goto error;);
570570

571571
dbh = Z_PDO_DBH_P(ZEND_THIS);
572-
PDO_CONSTRUCT_CHECK;
572+
PDO_CONSTRUCT_CHECK_WITH_CLEANUP(error);
573573

574574
H = (pdo_sqlite_db_handle *)dbh->driver_data;
575575

@@ -640,7 +640,7 @@ void pdo_sqlite_create_collation_internal(INTERNAL_FUNCTION_PARAMETERS, pdo_sqli
640640
ZEND_PARSE_PARAMETERS_END();
641641

642642
dbh = Z_PDO_DBH_P(ZEND_THIS);
643-
PDO_CONSTRUCT_CHECK;
643+
PDO_CONSTRUCT_CHECK_WITH_CLEANUP(cleanup_fcc);
644644

645645
H = (pdo_sqlite_db_handle *)dbh->driver_data;
646646

@@ -660,12 +660,12 @@ void pdo_sqlite_create_collation_internal(INTERNAL_FUNCTION_PARAMETERS, pdo_sqli
660660

661661
zend_release_fcall_info_cache(&fcc);
662662

663-
if (UNEXPECTED(EG(exception))) {
664-
RETURN_THROWS();
665-
}
666-
667663
efree(collation);
668664
RETURN_FALSE;
665+
666+
cleanup_fcc:
667+
zend_release_fcall_info_cache(&fcc);
668+
RETURN_THROWS();
669669
}
670670

671671
/* {{{ bool SQLite::sqliteCreateCollation(string name, callable callback)

ext/sqlite3/sqlite3.c

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

2218-
if (intern->funcs == NULL && intern->collations == NULL) {
2218+
if (intern->funcs == NULL && intern->collations == NULL && !ZEND_FCC_INITIALIZED(intern->authorizer_fcc)) {
22192219
/* Fast path without allocations */
22202220
*table = NULL;
22212221
*n = 0;
22222222
return zend_std_get_gc(object, table, n);
22232223
} else {
22242224
zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create();
22252225

2226+
php_sqlite3_gc_buffer_add_fcc(gc_buffer, &intern->authorizer_fcc);
2227+
22262228
php_sqlite3_func *func = intern->funcs;
22272229
while (func != NULL) {
22282230
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)