]> granicus.if.org Git - php/commitdiff
Fixed a memory leak in array_fill().
authorIlia Alshanetsky <iliaa@php.net>
Tue, 5 Nov 2002 16:19:19 +0000 (16:19 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 5 Nov 2002 16:19:19 +0000 (16:19 +0000)
The refcount hack is now done for ZE1 only and is slightly faster then the
original.
After this patch array_fill() can consistently create arrays with >65k elements.

ext/standard/array.c

index a1637072dd424cb3f93ca02f1bc277610294954d..4db2871f79d701bd6db9d101d027982e4a910e4c 100644 (file)
@@ -1397,11 +1397,14 @@ PHP_FUNCTION(array_fill)
        }
        newval = *val;
        while (i--) {
-               if (!(i%62000)) {
+#ifndef ZEND_ENGINE_2
+               if (newval->refcount >= 62000) {
                        MAKE_STD_ZVAL(newval);
                        *newval = **val;
                        zval_copy_ctor(newval);
+                       newval->refcount = 0;
                }
+#endif         
                zval_add_ref(&newval);
                zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &newval, sizeof(zval *), NULL);
        }