]> granicus.if.org Git - php/commitdiff
- Fixed memory leaks in readline_completion_function()
authorFelipe Pena <felipe@php.net>
Thu, 20 Nov 2008 22:23:53 +0000 (22:23 +0000)
committerFelipe Pena <felipe@php.net>
Thu, 20 Nov 2008 22:23:53 +0000 (22:23 +0000)
ext/readline/readline.c
ext/readline/tests/readline_completion_function_001.phpt [new file with mode: 0644]

index 878affabc54907d6d5224ea8d9137e440dcf5f7c..185492645b652c63b90e046d54b703839494f5cc 100644 (file)
@@ -169,8 +169,10 @@ PHP_MINIT_FUNCTION(readline)
 
 PHP_RSHUTDOWN_FUNCTION(readline)
 {
-       if (_readline_completion) 
+       if (_readline_completion) {
+               zval_dtor(_readline_completion);
                FREE_ZVAL(_readline_completion);
+       }
 #if HAVE_RL_CALLBACK_READ_CHAR
        if (_prepped_callback) {
                rl_callback_handler_remove();
@@ -494,6 +496,7 @@ PHP_FUNCTION(readline_completion_function)
        zval_dtor(&name);
 
        if (_readline_completion) {
+               zval_dtor(_readline_completion);
                FREE_ZVAL(_readline_completion);
        }
 
diff --git a/ext/readline/tests/readline_completion_function_001.phpt b/ext/readline/tests/readline_completion_function_001.phpt
new file mode 100644 (file)
index 0000000..828636c
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+readline_completion_function(): Basic test
+--SKIPIF--
+<?php if (!extension_loaded("readline")) die("skip"); ?>
+--FILE--
+<?php
+
+function foo() { }
+
+$data = array(
+       'foo',
+       'strtolower',
+       1,
+       1.1231
+);
+
+foreach ($data as $callback) {
+       readline_completion_function($callback);
+}
+
+?>
+--EXPECTF--
+Warning: readline_completion_function(): 1 is not callable in %s on line %d
+
+Warning: readline_completion_function(): 1.1231 is not callable in %s on line %d