|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-02-11 19:51 UTC] nikic@php.net
Description: ------------ <?php array_fill(PHP_INT_MAX, 2, '*') Leaks: [Sat Feb 11 20:47:35 2012] Script: 'reproduceCode4_memoryLeak.php' /home/nikic/dev/php-src-git/Zend/zend_vm_execute.h(2371) : Freeing 0xB786F010 (20 bytes), script=reproduceCode4_memoryLeak.php [Sat Feb 11 20:47:35 2012] Script: 'reproduceCode4_memoryLeak.php' /home/nikic/dev/php-src-git/Zend/zend_vm_execute.h(2374) : Freeing 0xB7870558 (1 bytes), script=reproduceCode4_memoryLeak.php /home/nikic/dev/php-src-git/Zend/zend_variables.c(121) : Actual location (location was relayed) === Total 2 memory leaks detected === Reason: zval_add_ref is called regardless of whether zend_hash_next_index_insert succeeds in http://lxr.php.net/opengrok/xref/PHP_TRUNK/ext/standard/array.c#1570. Patchesfill_up_to_possible_while_preventing_leak_61058 (last revision 2012-02-12 05:43 UTC by carloschilazo at gmail dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 17:00:01 2025 UTC |
There are lots of functions/codes doesn't check the return value of zend_hash_next_index_insert(and other variants of zend_hash_update_**). So, IMO, there should be some familar issues there. if we only focus on this one, a simple patch will be(but I think it's no needed to fix this, since this really a intentional behavior :) thanks ): Index: ext/standard/array.c =================================================================== --- ext/standard/array.c (revision 323122) +++ ext/standard/array.c (working copy) @@ -1564,11 +1564,15 @@ num--; zval_add_ref(&val); - zend_hash_index_update(Z_ARRVAL_P(return_value), start_key, &val, sizeof(zval *), NULL); + if (zend_hash_index_update(Z_ARRVAL_P(return_value), start_key, &val, sizeof(zval *), NULL) == FAILURE) { + zval_ptr_dtor(&val); + } while (num--) { zval_add_ref(&val); - zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &val, sizeof(zval *), NULL); + if (zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &val, sizeof(zval *), NULL) == FAILURE) { + zval_ptr_dtor(&val); + } } } /* }}} */