Skip to content

Commit 09afbc7

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 09afbc7

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
 

‎ext/pdo/pdo_stmt.c

+6
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ 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+
<<<<<<< Updated upstream
215216
stmt->lazy_object_ref = &row->std;
217+
=======
218+
object_properties_init(&row->std, pdo_row_ce);
219+
ZVAL_OBJ(&stmt->lazy_object_ref, &row->std);
220+
>>>>>>> Stashed changes
216221
GC_ADDREF(&stmt->std);
217222
GC_DELREF(&row->std);
218223
}
@@ -2405,6 +2410,7 @@ static zend_object *pdo_row_new(zend_class_entry *ce)
24052410
{
24062411
pdo_row_t *row = zend_object_alloc(sizeof(pdo_row_t), ce);
24072412
zend_object_std_init(&row->std, ce);
2413+
object_properties_init(&row->std, pdo_row_ce);
24082414

24092415
return &row->std;
24102416
}

‎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)
Failed to load comments.