php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61088 Memory leak in readline_callback_handler_install
Submitted: 2012-02-14 18:14 UTC Modified: 2012-03-11 09:20 UTC
From: nikic@php.net Assigned: laruence (profile)
Status: Closed Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2012-02-14 18:14 UTC] nikic@php.net
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);



Patches

readline.patch (last revision 2012-02-14 18:14 UTC by nikic@php.net)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-14 18:14 UTC] nikic@php.net
The following patch has been added/updated:

Patch Name: readline.patch
Revision:   1329243283
URL:        https://bugs.php.net/patch-display.php?bug=61088&patch=readline.patch&revision=1329243283
 [2012-02-16 02:15 UTC] laruence@php.net
-Assigned To: +Assigned To: laruence
 [2012-03-11 09:19 UTC] laruence@php.net
Automatic comment from SVN on behalf of laruence
Revision: http://svn.php.net/viewvc/?view=revision&revision=324104
Log: Fixed bug #61088 (Memory leak in readline_callback_handler_install).
 [2012-03-11 09:20 UTC] laruence@php.net
-Status: Assigned +Status: Closed
 [2012-03-11 09:20 UTC] laruence@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-04-18 09:45 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7059735b1de549fa6bf7c8e5e09e11c6950f86a0
Log: Fixed bug #61088 (Memory leak in readline_callback_handler_install).
 [2012-07-24 23:36 UTC] rasmus@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7059735b1de549fa6bf7c8e5e09e11c6950f86a0
Log: Fixed bug #61088 (Memory leak in readline_callback_handler_install).
 [2013-11-17 09:33 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7059735b1de549fa6bf7c8e5e09e11c6950f86a0
Log: Fixed bug #61088 (Memory leak in readline_callback_handler_install).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC