From: nikic Operating system: PHP version: Irrelevant Package: *General Issues Bug Type: Bug Bug description:Memory leak in readline_callback_handler_install
Description: ------------ $callback = function() {}; readline_callback_handler_install('***', $callback); Leaks: ***[Tue Feb 14 19:01:11 2012] Script: 'reproduceCode3_memoryLeak.php' /home/nikic/dev/php-src/ext/readline/readline.c(579) : Freeing 0xB78618F4 (20 bytes), script=reproduceCode3_memoryLeak.php === Total 1 memory leaks detected === Reason is incorrect copying of a zval in http://lxr.php.net/opengrok/xref/PHP_TRUNK/ext/readline/readline.c#579. I was able to fix it using this simple patch: diff --git a/ext/readline/readline.c b/ext/readline/readline.c index 22521e6..c9389fc 100644 --- a/ext/readline/readline.c +++ b/ext/readline/readline.c @@ -576,9 +576,8 @@ PHP_FUNCTION(readline_callback_handler_install) FREE_ZVAL(_prepped_callback); } - MAKE_STD_ZVAL(_prepped_callback); - *_prepped_callback = *callback; - zval_copy_ctor(_prepped_callback); + ALLOC_ZVAL(_prepped_callback); + MAKE_COPY_ZVAL(&callback, _prepped_callback); rl_callback_handler_install(prompt, php_rl_callback_handler); -- Edit bug report at https://bugs.php.net/bug.php?id=61088&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61088&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61088&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61088&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=61088&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61088&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=61088&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=61088&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=61088&r=needscript Try newer version: https://bugs.php.net/fix.php?id=61088&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=61088&r=support Expected behavior: https://bugs.php.net/fix.php?id=61088&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=61088&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=61088&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=61088&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61088&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=61088&r=dst IIS Stability: https://bugs.php.net/fix.php?id=61088&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=61088&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=61088&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=61088&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=61088&r=mysqlcfg