Skip to content

Commit 881416c

Browse files
committed
Fixed bug #63680 (Memleak in splfixedarray with cycle reference)
1 parent 73e66ff commit 881416c

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ PHP NEWS
6060
. Fixed bug #49341 (Add SO_REUSEPORT support for socket_set_option()).
6161
(Igor Wiedler, Lars)
6262

63+
- SPL
64+
. Fixed bug #63680 (Memleak in splfixedarray with cycle reference). (Laruence)
65+
6366
22 Nov 2012, PHP 5.4.9
6467

6568
- Core:

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++) {
@@ -1091,6 +1108,7 @@ PHP_MINIT_FUNCTION(spl_fixedarray)
10911108
spl_handler_SplFixedArray.has_dimension = spl_fixedarray_object_has_dimension;
10921109
spl_handler_SplFixedArray.count_elements = spl_fixedarray_object_count_elements;
10931110
spl_handler_SplFixedArray.get_properties = spl_fixedarray_object_get_properties;
1111+
spl_handler_SplFixedArray.get_gc = spl_fixedarray_object_get_gc;
10941112

10951113
REGISTER_SPL_IMPLEMENTS(SplFixedArray, Iterator);
10961114
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)