Commit:    881416cda670a7ddb94db11a41d4929425da7d61
Author:    Dmitry Stogov <dmi...@zend.com>         Wed, 5 Dec 2012 17:53:26 
+0400
Parents:   73e66ff1bd9b0e79f766c144dacd2dbab6b960b7
Branches:  PHP-5.4 PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=881416cda670a7ddb94db11a41d4929425da7d61

Log:
Fixed bug #63680 (Memleak in splfixedarray with cycle reference)

Bugs:
https://bugs.php.net/63680

Changed paths:
  M  NEWS
  M  ext/spl/spl_fixedarray.c
  A  ext/spl/tests/bug63680.phpt


Diff:
diff --git a/NEWS b/NEWS
index 4629c41..2023198 100644
--- a/NEWS
+++ b/NEWS
@@ -60,6 +60,9 @@ PHP                                                           
             NEWS
   . Fixed bug #49341 (Add SO_REUSEPORT support for socket_set_option()).
     (Igor Wiedler, Lars)
 
+- SPL
+  . Fixed bug #63680 (Memleak in splfixedarray with cycle reference). 
(Laruence)
+
 22 Nov 2012, PHP 5.4.9
 
 - Core:
diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c
index 244bd3e..6a4d785 100644
--- a/ext/spl/spl_fixedarray.c
+++ b/ext/spl/spl_fixedarray.c
@@ -147,13 +147,30 @@ static void spl_fixedarray_copy(spl_fixedarray *to, 
spl_fixedarray *from TSRMLS_
 }
 /* }}} */
 
+static HashTable* spl_fixedarray_object_get_gc(zval *obj, zval ***table, int 
*n TSRMLS_DC) /* {{{{ */
+{
+       spl_fixedarray_object *intern  = 
(spl_fixedarray_object*)zend_object_store_get_object(obj TSRMLS_CC);
+       HashTable *ht = zend_std_get_properties(obj TSRMLS_CC);
+
+       if (intern->array) {
+               *table = intern->array->elements;
+               *n = intern->array->size;
+       } else {
+               *table = NULL;
+               *n = 0;
+       }
+
+       return ht;
+}
+/* }}}} */
+
 static HashTable* spl_fixedarray_object_get_properties(zval *obj TSRMLS_DC) /* 
{{{{ */
 {
        spl_fixedarray_object *intern  = 
(spl_fixedarray_object*)zend_object_store_get_object(obj TSRMLS_CC);
        HashTable *ht = zend_std_get_properties(obj TSRMLS_CC);
        int  i = 0;
 
-       if (intern->array && !GC_G(gc_active)) {
+       if (intern->array) {
                int j = zend_hash_num_elements(ht);
 
                for (i = 0; i < intern->array->size; i++) {
@@ -1091,6 +1108,7 @@ PHP_MINIT_FUNCTION(spl_fixedarray)
        spl_handler_SplFixedArray.has_dimension   = 
spl_fixedarray_object_has_dimension;
        spl_handler_SplFixedArray.count_elements  = 
spl_fixedarray_object_count_elements;
        spl_handler_SplFixedArray.get_properties  = 
spl_fixedarray_object_get_properties;
+       spl_handler_SplFixedArray.get_gc          = 
spl_fixedarray_object_get_gc;
 
        REGISTER_SPL_IMPLEMENTS(SplFixedArray, Iterator);
        REGISTER_SPL_IMPLEMENTS(SplFixedArray, ArrayAccess);
diff --git a/ext/spl/tests/bug63680.phpt b/ext/spl/tests/bug63680.phpt
new file mode 100644
index 0000000..3a20c4b
--- /dev/null
+++ b/ext/spl/tests/bug63680.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Bug #63680 (Memleak in splfixedarray with cycle reference)
+--FILE--
+<?php
+function dummy() {
+    $a = new SplFixedArray(1);
+    $b = new SplFixedArray(1);
+    $a[0] = $b;
+    $b[0] = $a;
+}
+
+dummy();
+var_dump(gc_collect_cycles());
+?>
+--EXPECT--
+int(2)


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to