note 99120 added to function.gmp-cmp

From: Date: Wed, 28 Jul 2010 20:43:54 +0000
Subject: note 99120 added to function.gmp-cmp
Groups: php.notes 
Request: Send a blank email to php-notes+get-171194@lists.php.net to get a copy of this message
I've encountered a memory leak in gmp_cmp if a literal string is used as the second value inside of loops. A workaround is to initialize first, then use the variable. I wasn't able to generate a minimum code sample, it's something more complicated, but I was able to fix it as follows: <?php $x = gmp_init(strval(mt_rand())); // Depending on surrounding code, may have leaks while (true) { if (!gmp_cmp($x, '1')) print 'one'."\n"; } // Usually doesn't have leaks $one = gmp_init('1'); while (true) { if (!gmp_cmp($x, $one)) print 'one'."\n"; } ?> ---- Server IP: 72.55.140.6 Probable Submitter: 199.243.246.66 ---- Manual Page -- http://www.php.net/manual/en/function.gmp-cmp.php Edit -- https://master.php.net/note/edit/99120 Del: integrated -- https://master.php.net/note/delete/99120/integrated Del: useless -- https://master.php.net/note/delete/99120/useless Del: bad code -- https://master.php.net/note/delete/99120/bad+code Del: spam -- https://master.php.net/note/delete/99120/spam Del: non-english -- https://master.php.net/note/delete/99120/non-english Del: in docs -- https://master.php.net/note/delete/99120/in+docs Del: other reasons-- https://master.php.net/note/delete/99120 Reject -- https://master.php.net/note/reject/99120 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#171194) next »