Skip to content

Commit 635fe26

Browse files
committed
Fix memory leaks in pdo_sqlite callback registration
* We need to clean the trampoline if the construction check fails * Checking for an exception and then returning causes a leak on `collation`. Returning early is pointless anyway. Closes GH-17904.
1 parent 7603509 commit 635fe26

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ PHP NEWS
6060
. Fixed GH-17837 ()::getColumnMeta() on unexecuted statement segfaults).
6161
(cmb)
6262
. Fix cycle leak in sqlite3 setAuthorizer(). (nielsdos)
63+
. Fix memory leaks in pdo_sqlite callback registration. (nielsdos)
6364

6465
- Phar:
6566
. Fixed bug GH-17808: PharFileInfo refcount bug. (nielsdos)

ext/pdo_sqlite/sqlite_driver.c

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

515515
dbh = Z_PDO_DBH_P(ZEND_THIS);
516-
PDO_CONSTRUCT_CHECK;
516+
PDO_CONSTRUCT_CHECK_WITH_CLEANUP(error);
517517

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

@@ -571,7 +571,7 @@ void pdo_sqlite_create_aggregate_internal(INTERNAL_FUNCTION_PARAMETERS)
571571
ZEND_PARSE_PARAMETERS_END_EX(goto error;);
572572

573573
dbh = Z_PDO_DBH_P(ZEND_THIS);
574-
PDO_CONSTRUCT_CHECK;
574+
PDO_CONSTRUCT_CHECK_WITH_CLEANUP(error);
575575

576576
H = (pdo_sqlite_db_handle *)dbh->driver_data;
577577

@@ -643,7 +643,7 @@ void pdo_sqlite_create_collation_internal(INTERNAL_FUNCTION_PARAMETERS, pdo_sqli
643643
ZEND_PARSE_PARAMETERS_END();
644644

645645
dbh = Z_PDO_DBH_P(ZEND_THIS);
646-
PDO_CONSTRUCT_CHECK;
646+
PDO_CONSTRUCT_CHECK_WITH_CLEANUP(cleanup_fcc);
647647

648648
H = (pdo_sqlite_db_handle *)dbh->driver_data;
649649

@@ -663,12 +663,12 @@ void pdo_sqlite_create_collation_internal(INTERNAL_FUNCTION_PARAMETERS, pdo_sqli
663663

664664
zend_release_fcall_info_cache(&fcc);
665665

666-
if (UNEXPECTED(EG(exception))) {
667-
RETURN_THROWS();
668-
}
669-
670666
efree(collation);
671667
RETURN_FALSE;
668+
669+
cleanup_fcc:
670+
zend_release_fcall_info_cache(&fcc);
671+
RETURN_THROWS();
672672
}
673673

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

0 commit comments

Comments
 (0)