Skip to content

Commit 2a1aa8c

Browse files
committed
Fix GH-13998: Manage refcount of agg_context->val correctly (#14004)
When step_callback fails, agg_context->val is passed dtor, but agg_context->val is also used in final_callback regardless of the success/failure of step_callback, so should not call dtor. closes #14004 fixes #13998
1 parent b3e26c3 commit 2a1aa8c

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ PHP NEWS
3636

3737
- PDO SQLite:
3838
. Fix GH-13984 (Buffer size is now checked before memcmp). (Saki Takamachi)
39+
. Fix GH-13998 (Manage refcount of agg_context->val correctly).
40+
(Saki Takamachi)
3941

4042
- Phar:
4143
. Fixed bug GH-13836 (Renaming a file in a Phar to an already existing

ext/pdo_sqlite/sqlite_driver.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ static int do_callback(struct pdo_sqlite_fci *fc, zval *cb,
441441
* the context */
442442
if (agg_context) {
443443
if (Z_ISUNDEF(retval)) {
444-
zval_ptr_dtor(&agg_context->val);
445444
return FAILURE;
446445
}
447446
zval_ptr_dtor(Z_REFVAL(agg_context->val));

ext/pdo_sqlite/tests/gh13998.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Fix GH-13998: Manage refcount of agg_context->val correctly
3+
--EXTENSIONS--
4+
pdo_sqlite
5+
--FILE--
6+
<?php
7+
$step = function () {
8+
throw new Exception();
9+
};
10+
$finalize = function () {
11+
};
12+
13+
$db = new PDO('sqlite::memory:');
14+
$db->query('CREATE TABLE test (a int, b int)');
15+
$stmt = $db->query('INSERT INTO test VALUES (1, 1), (2, 2), (3, 3)');
16+
$db->sqliteCreateAggregate('S', $step, $finalize, 1);
17+
18+
try {
19+
$db->query('SELECT S(a) FROM test');
20+
} catch (Exception $e) {
21+
echo 'done!';
22+
}
23+
?>
24+
--EXPECT--
25+
done!

0 commit comments

Comments
 (0)