Skip to content

Commit 34d8da2

Browse files
committedMar 19, 2025
Fix phpGH-18114: pdo lazy object crash
Since 0537968, the properties are no longer initialized. So we call object_properties_init to handle that correctly. Lower branches have a memory leak, but that requires a separate fix.
1 parent 6d6ac81 commit 34d8da2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
 

‎ext/pdo/pdo_stmt.c

+2
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ static void pdo_get_lazy_object(pdo_stmt_t *stmt, zval *return_value) /* {{{ */
212212
pdo_row_t *row = zend_object_alloc(sizeof(pdo_row_t), pdo_row_ce);
213213
row->stmt = stmt;
214214
zend_object_std_init(&row->std, pdo_row_ce);
215+
object_properties_init(&row->std, pdo_row_ce);
215216
stmt->lazy_object_ref = &row->std;
216217
GC_ADDREF(&stmt->std);
217218
GC_DELREF(&row->std);
@@ -2405,6 +2406,7 @@ static zend_object *pdo_row_new(zend_class_entry *ce)
24052406
{
24062407
pdo_row_t *row = zend_object_alloc(sizeof(pdo_row_t), ce);
24072408
zend_object_std_init(&row->std, ce);
2409+
object_properties_init(&row->std, pdo_row_ce);
24082410

24092411
return &row->std;
24102412
}

‎ext/pdo_sqlite/tests/gh18114.phpt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-18114 (pdo lazy object crash)
3+
--EXTENSIONS--
4+
pdo_sqlite
5+
--XLEAK--
6+
See https://github.com/php/php-src/issues/18114#issuecomment-2738069692, will be fixed in a later PR on lower branches
7+
--FILE--
8+
<?php
9+
$db = new PDO('sqlite::memory:');
10+
$x = $db->query('select 1 as queryString');
11+
foreach ($x->fetch(PDO::FETCH_LAZY) as $entry) {
12+
var_dump($entry);
13+
}
14+
echo "Done\n";
15+
?>
16+
--EXPECT--
17+
Done

0 commit comments

Comments
 (0)