Ask a Question related to PHP Bugs, Design and Development.
-
nlopess@php.net #1
#36427 [Asn->Csd]: proc_open() / proc_close() leak handles on Windows XP
ID: 36427
Updated by: [email]nlopess@php.net[/email]
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
[url]http://snaps.php.net/[/url].
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]nlopess@php.net[/email]
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
[url]http://bugs.php.net/36427[/url]
--
Edit this bug report at [url]http://bugs.php.net/?id=36427&edit=1[/url]
nlopess@php.net Guest
-
#34794 [Asn->Csd]: proc_close() hangs when used with two processes
ID: 34794 Updated by: nlopess@php.net Reported By: e-t172 at e-t172 dot net -Status: Assigned +Status: ... -
proc_open() Help
I'm struggling with proc_open(). What I'm trying to do is conduct an sftp session. The process appears to open fine, but anything I send to it with... -
#22999 [Asn]: proc_close() sometimes returns -1 when called process exited with status of 0
ID: 22999 Updated by: wez@php.net Reported By: phil at concretecomputing dot co dot uk Status: Assigned Bug... -
#21077 [Fbk->Opn]: proc_open hangs
ID: 21077 Updated by: msopacua@php.net Reported By: msopacua@php.net -Status: Feedback +Status: Open... -
#22999 [Com]: proc_close() sometimes returns -1 when called process exited with status of 0
ID: 22999 Comment by: vojtech at fotobanka dot cz Reported By: phil at concretecomputing dot co dot uk Status: ...



Reply With Quote

