ID:               36427
 Updated by:       [EMAIL PROTECTED]
 Reported By:      pgj at ds-fr dot com
-Status:           Assigned
+Status:           Closed
 Bug Type:         Program Execution
 Operating System: windows XP SP2 Windows 2000 SP4
 PHP Version:      5.1.2, 4.4.2
 Assigned To:      wez
 New Comment:

This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------

[2006-06-01 16:13:17] jdolecek at NetBSD dot org

Alternative (simplier) patch:

--- ext/standard/proc_open.c.orig       2006-06-01 18:09:51.000000000
+0200
+++ ext/standard/proc_open.c
@@ -670,7 +670,10 @@ PHP_FUNCTION(proc_open)
                                }

 #ifdef PHP_WIN32
-                               descriptors[ndesc].childend =
(HANDLE)_get_osfhandle(fd);
+                               /* dup the handle, and close the
original descriptor to
+                                * avoid leak */
+                               descriptors[ndesc].childend =
dup_fd_as_handle(fd);
+                               _close(fd);
 #else
                                descriptors[ndesc].childend = fd;
 #endif

------------------------------------------------------------------------

[2006-05-29 12:05:44] pgj at ds-fr dot com

Your correction works on 4.4.2 on windows, no more bugs after 10000
proc_open.
Thanks a lot

------------------------------------------------------------------------

[2006-05-28 20:57:35] jdolecek at NetBSD dot org

It appears the problem is actually due to way Windows internally
emulate POSIX file descriptors, i.e. the process runs out of the
allowed count of the 'POSIX' file descriptors tracked in the C library,
not handles per se.

This is supported by Windows process viewer, which shows ~constant
number of handles for PHP process during the script run, particularily
same number of handles when it runs OK and when it starts giving the
error.

Note the problem only appears when using 'file' in descriptorspec,
using 'pipe' instead does workaround the problem.

I believe the problem can be fixed by consistently closing the file
descriptors rather then just the handles, i.e something along:

--- ext/standard/proc_open.c.orig       2006-05-28 21:51:09.000000000
+0200
+++ ext/standard/proc_open.c
@@ -462,6 +462,9 @@ static inline HANDLE dup_fd_as_handle(in
 struct php_proc_open_descriptor_item {
        int index;                                                     
/* desired fd number in child process */
        php_file_descriptor_t parentend, childend;      /* fds for
pipes in parent/child */
+#ifdef PHP_WIN32
+    int childend_desc;
+#endif
        int mode;                                                      
/* mode for proc_open code */
        int mode_flags;                                         /* mode
flags for opening fds */
 };
@@ -671,6 +674,7 @@ PHP_FUNCTION(proc_open)

 #ifdef PHP_WIN32
                                descriptors[ndesc].childend =
(HANDLE)_get_osfhandle(fd);
+                               descriptors[ndesc].childend_desc = fd;
 #else
                                descriptors[ndesc].childend = fd;
 #endif
@@ -901,6 +905,11 @@ PHP_FUNCTION(proc_open)
                char *mode_string=NULL;
                php_stream *stream = NULL;

+#ifdef PHP_WIN32
+               if (descriptors[i].childend_desc)
+                       _close(descriptors[i].childend_desc); /* closes
also the handle */
+#endif
+
                close_descriptor(descriptors[i].childend);

                switch (descriptors[i].mode & ~DESC_PARENT_MODE_WRITE)
{


I cannot check this, since I haven't succeeded in setting up a build
environment on MS Windows for PHP sources.

------------------------------------------------------------------------

[2006-02-21 18:11:58] pgj at ds-fr dot com

Same problem with php 5.1.2

------------------------------------------------------------------------

[2006-02-19 01:38:59] [EMAIL PROTECTED]

While I can reproduce the problem, I couldn't spot the error at first
sight, because the code is very complex (and without valgrind even
worst..)

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/36427

-- 
Edit this bug report at http://bugs.php.net/?id=36427&edit=1

Reply via email to