moriyoshi               Sun Jul 13 15:46:39 2003 EDT

  Added files:                 (Branch: PHP_4_3)
    /php-src/ext/standard/tests/file    proc_open01.phpt 

  Modified files:              
    /php-src/ext/standard       exec.c 
  Log:
  MFH: fixed leaks that occurs if the third parameter already contains a valid
  value.
  
  
Index: php-src/ext/standard/exec.c
diff -u php-src/ext/standard/exec.c:1.84.2.8 php-src/ext/standard/exec.c:1.84.2.9
--- php-src/ext/standard/exec.c:1.84.2.8        Wed Apr 16 18:57:15 2003
+++ php-src/ext/standard/exec.c Sun Jul 13 15:46:39 2003
@@ -15,7 +15,7 @@
    | Author: Rasmus Lerdorf                                               |
    +----------------------------------------------------------------------+
  */
-/* $Id: exec.c,v 1.84.2.8 2003/04/16 22:57:15 moriyoshi Exp $ */
+/* $Id: exec.c,v 1.84.2.9 2003/07/13 19:46:39 moriyoshi Exp $ */
 
 #include <stdio.h>
 #include "php.h"
@@ -690,7 +690,7 @@
        pid_t child;
 #endif
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "saz/", &command,
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "saz", &command,
                                &command_len, &descriptorspec, &pipes) == FAILURE) {
                RETURN_FALSE;
        }
@@ -941,6 +941,10 @@
        /* we forked/spawned and this is the parent */
 
        efree(command);
+
+       if (pipes != NULL) {
+               zval_dtor(pipes);
+       }
        array_init(pipes);
 
        /* clean up all the child ends and then open streams on the parent

Index: php-src/ext/standard/tests/file/proc_open01.phpt
+++ php-src/ext/standard/tests/file/proc_open01.phpt
--TEST--
proc_open() regression test 1 (proc_open() leak)
--FILE--
<?php
$pipes = array(1, 2, 3);
$orig_pipes = $pipes;
$proc = proc_open(
        $_ENV['TEST_PHP_EXECUTABLE'],
        array(0 => array('pipe', 'r'), 1 => array('pipe', 'w')),
        $pipes
);
if ($proc === false) {
        print "something went wrong.\n";
}
var_dump($pipes);
stream_set_blocking($pipes[1], FALSE);
$test_string = "yay!\n";
fwrite($pipes[0], $test_string);
fflush($pipes[0]);
fclose($pipes[0]);
$cnt = '';
for ($left = strlen($test_string); $left > 0;) { 
        $read_fds = array($pipes[1]);
        $retval = stream_select($read_fds, $write_fds = NULL, $exp_fds = NULL, 1);
        if ($retval === false) {
                print "select() failed\n";
                break;
        }
        if ($retval === 0) {
                print "timed out\n";
                break;
        }
        $buf = fread($pipes[1], 1024);
        $cnt .= $buf;
        $left -= strlen($buf);
}
var_dump($cnt);
fclose($pipes[1]);
proc_close($proc);
var_dump($orig_pipes);
?>
--EXPECTF--
array(2) {
  [0]=>
  resource(%d) of type (stream)
  [1]=>
  resource(%d) of type (stream)
}
string(5) "yay!
"
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to