Skip to content

Commit 73601e2

Browse files
committed
Merge branch 'PHP-5.5'
* PHP-5.5: Fixed bug #63680 (Memleak in splfixedarray with cycle reference)
2 parents 55e1a97 + 274ceb3 commit 73601e2

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

ext/spl/spl_fixedarray.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,30 @@ static void spl_fixedarray_copy(spl_fixedarray *to, spl_fixedarray *from TSRMLS_
147147
}
148148
/* }}} */
149149

150+
static HashTable* spl_fixedarray_object_get_gc(zval *obj, zval ***table, int *n TSRMLS_DC) /* {{{{ */
151+
{
152+
spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(obj TSRMLS_CC);
153+
HashTable *ht = zend_std_get_properties(obj TSRMLS_CC);
154+
155+
if (intern->array) {
156+
*table = intern->array->elements;
157+
*n = intern->array->size;
158+
} else {
159+
*table = NULL;
160+
*n = 0;
161+
}
162+
163+
return ht;
164+
}
165+
/* }}}} */
166+
150167
static HashTable* spl_fixedarray_object_get_properties(zval *obj TSRMLS_DC) /* {{{{ */
151168
{
152169
spl_fixedarray_object *intern = (spl_fixedarray_object*)zend_object_store_get_object(obj TSRMLS_CC);
153170
HashTable *ht = zend_std_get_properties(obj TSRMLS_CC);
154171
int i = 0;
155172

156-
if (intern->array && !GC_G(gc_active)) {
173+
if (intern->array) {
157174
int j = zend_hash_num_elements(ht);
158175

159176
for (i = 0; i < intern->array->size; i++) {
@@ -1124,6 +1141,7 @@ PHP_MINIT_FUNCTION(spl_fixedarray)
11241141
spl_handler_SplFixedArray.has_dimension = spl_fixedarray_object_has_dimension;
11251142
spl_handler_SplFixedArray.count_elements = spl_fixedarray_object_count_elements;
11261143
spl_handler_SplFixedArray.get_properties = spl_fixedarray_object_get_properties;
1144+
spl_handler_SplFixedArray.get_gc = spl_fixedarray_object_get_gc;
11271145

11281146
REGISTER_SPL_IMPLEMENTS(SplFixedArray, Iterator);
11291147
REGISTER_SPL_IMPLEMENTS(SplFixedArray, ArrayAccess);

ext/spl/tests/bug63680.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #63680 (Memleak in splfixedarray with cycle reference)
3+
--FILE--
4+
<?php
5+
function dummy() {
6+
$a = new SplFixedArray(1);
7+
$b = new SplFixedArray(1);
8+
$a[0] = $b;
9+
$b[0] = $a;
10+
}
11+
12+
dummy();
13+
var_dump(gc_collect_cycles());
14+
?>
15+
--EXPECT--
16+
int(2)

0 commit comments

Comments
 (0)