Skip to content

Commit

Permalink
Merge branch 'PHP-8.4'
Browse files Browse the repository at this point in the history
* PHP-8.4:
  Fix memory leaks in pdo_sqlite callback registration
  Fix cycle leak in sqlite3 setAuthorizer()
  • Loading branch information
nielsdos committed Feb 23, 2025
2 parents 6746634 + 635fe26 commit 6a4b0c9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
14 changes: 7 additions & 7 deletions ext/pdo_sqlite/sqlite_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ void pdo_sqlite_create_function_internal(INTERNAL_FUNCTION_PARAMETERS)
ZEND_PARSE_PARAMETERS_END_EX(goto error;);

dbh = Z_PDO_DBH_P(ZEND_THIS);
PDO_CONSTRUCT_CHECK;
PDO_CONSTRUCT_CHECK_WITH_CLEANUP(error);

H = (pdo_sqlite_db_handle *)dbh->driver_data;

Expand Down Expand Up @@ -569,7 +569,7 @@ void pdo_sqlite_create_aggregate_internal(INTERNAL_FUNCTION_PARAMETERS)
ZEND_PARSE_PARAMETERS_END_EX(goto error;);

dbh = Z_PDO_DBH_P(ZEND_THIS);
PDO_CONSTRUCT_CHECK;
PDO_CONSTRUCT_CHECK_WITH_CLEANUP(error);

H = (pdo_sqlite_db_handle *)dbh->driver_data;

Expand Down Expand Up @@ -640,7 +640,7 @@ void pdo_sqlite_create_collation_internal(INTERNAL_FUNCTION_PARAMETERS, pdo_sqli
ZEND_PARSE_PARAMETERS_END();

dbh = Z_PDO_DBH_P(ZEND_THIS);
PDO_CONSTRUCT_CHECK;
PDO_CONSTRUCT_CHECK_WITH_CLEANUP(cleanup_fcc);

H = (pdo_sqlite_db_handle *)dbh->driver_data;

Expand All @@ -660,12 +660,12 @@ void pdo_sqlite_create_collation_internal(INTERNAL_FUNCTION_PARAMETERS, pdo_sqli

zend_release_fcall_info_cache(&fcc);

if (UNEXPECTED(EG(exception))) {
RETURN_THROWS();
}

efree(collation);
RETURN_FALSE;

cleanup_fcc:
zend_release_fcall_info_cache(&fcc);
RETURN_THROWS();
}

/* {{{ bool SQLite::sqliteCreateCollation(string name, callable callback)
Expand Down
4 changes: 3 additions & 1 deletion ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -2215,14 +2215,16 @@ static HashTable *php_sqlite3_get_gc(zend_object *object, zval **table, int *n)
{
php_sqlite3_db_object *intern = php_sqlite3_db_from_obj(object);

if (intern->funcs == NULL && intern->collations == NULL) {
if (intern->funcs == NULL && intern->collations == NULL && !ZEND_FCC_INITIALIZED(intern->authorizer_fcc)) {
/* Fast path without allocations */
*table = NULL;
*n = 0;
return zend_std_get_gc(object, table, n);
} else {
zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create();

php_sqlite3_gc_buffer_add_fcc(gc_buffer, &intern->authorizer_fcc);

php_sqlite3_func *func = intern->funcs;
while (func != NULL) {
php_sqlite3_gc_buffer_add_fcc(gc_buffer, &func->func);
Expand Down
21 changes: 21 additions & 0 deletions ext/sqlite3/tests/setauthorizer_cycle_leak.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
setAuthorizer() cycle leak
--EXTENSIONS--
sqlite3
--FILE--
<?php
class Foo extends Sqlite3 {
public function __construct() {
parent::__construct(":memory:");
$this->setAuthorizer([$this, "foo"]);
}

public function foo() {}
}

$test = new Foo;

echo "Done\n";
?>
--EXPECT--
Done

0 comments on commit 6a4b0c9

Please sign in to comment.