Re: [PATCH] A suggested fix for bug #19943 (Re: [PHP-DEV] bug #19943)
| From: | Andi Gutmans | Date: | Tue, 05 Nov 2002 18:10:11 +0000 |
| Subject: | Re: [PATCH] A suggested fix for bug #19943 (Re: [PHP-DEV] bug #19943) | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-90543@lists.php.net to get a copy of this message | ||
We'll take a look at this.
Thanks,
Andi
At 07:48 AM 11/6/2002 +0900, Moriyoshi Koizumi wrote:
The attached patch may be a fix for that bug. Hope it works. Moriyoshi Moriyoshi Koizumi <moriyoshi@at.wakwak.com> wrote: I looked into it, and I've found you really got a point. --------------------------- <?php $ragged = array(); $ragged[0] = "a"; $ragged[0][0] = array("1"); var_dump($ragged); ?> --------------------------- The first script causes no leaks, while the second does: --------------------------- <?php $ragged = array(); $ragged[0] = "a"; $ragged[0][0] = (string)array("1"); var_dump($ragged); ?> --------------------------- Thanks for your insight. Moriyoshi "Ilia A." <ilia@prohost.org> wrote:I agree with you that this bug may not be critical, I am not certainwhy itwas marked as such, however I do believe this is a bug that should befixed.If my understand of the situation is correct, the memory leak is theresult oforiginal $ragged[$count] = "$count"; expression. At this point ZEcreates aZVAL that contains a 2 byte string value, number + \0. When $ragged[$count]['idx'] = 'ragged '.$count; is executed, theoriginal zvalcontaining a string is converted to an array. During this conversion the string value is not freed and the result is a memory leak. Ilia On November 5, 2002 01:45 pm, Moriyoshi Koizumi wrote:-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.phpThis appears not a bug, but an expected behaviour for me. Let's change it from "Critial" to "Won't Fix" or so on. --------------------------------------------------------------- <?php $ragged = array(); for ($count = 0; $count < 10; $count++) {-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php$ragged[$count] = "$count"; $ragged[$count]['idx'] = "$count";} for ($count = 0; $count < 10; $count++) {printf("single %d: %s\n", $count, $ragged[$count]); printf("ragged %d: %s\n", $count, $ragged[$count]['idx']);} ?> --------------------------------------------------------------- The above snippet is actually a variant of the following code: --------------------------------------------------------------- <?php $ragged = array(); for ($count = 0; $count < 10; $count++) {$ragged[$count] = (string)$count; $ragged[$count]{(int)'idx'} = (string)$count;} for ($count = 0; $count < 10; $count++) {printf("single %d: %s\n", $count, $ragged[$count]); printf("ragged %d: %s\n", $count, $ragged[$count]{(int)'idx'});} ?> --------------------------------------------------------------- Then, "Cannot use a scalar value as an array" warnings are due to applications of braces for non-string variables. But I can't still explain why leaks occured. Moriyoshi