You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by iv...@apache.org on 2023/01/21 15:52:22 UTC
svn commit: r1906885 - in /apr/apr/trunk: CHANGES threadproc/win32/proc.c
Author: ivan
Date: Sat Jan 21 15:52:22 2023
New Revision: 1906885
URL: http://svn.apache.org/viewvc?rev=1906885&view=rev
Log:
Fix potential handle leak when apr_proc_create() is used from from multiple
threads on Windows.
* threadproc/win32/proc.c
(apr_proc_create): Close our side of pipes before releasing lock: otherwise
they could like to other process when apr_proc_create() is used from from
multiple threads.
Modified:
apr/apr/trunk/CHANGES
apr/apr/trunk/threadproc/win32/proc.c
Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewvc/apr/apr/trunk/CHANGES?rev=1906885&r1=1906884&r2=1906885&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES [utf-8] (original)
+++ apr/apr/trunk/CHANGES [utf-8] Sat Jan 21 15:52:22 2023
@@ -271,6 +271,9 @@ Changes for APR 2.0.0
*) apr_proc_create(): Fix incorrect error handling when pipes are redirected
on Windows [Ivan Zhakov]
+ *) apr_proc_create(): Fix potential handle leak when apr_proc_create() is used
+ from from multiple threads on Windows [Ivan Zhakov]
+
Changes for APR and APR-util 1.7.x and later:
*) http://svn.apache.org/viewvc/apr/apr/branches/1.7.x/CHANGES?view=markup
Modified: apr/apr/trunk/threadproc/win32/proc.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/threadproc/win32/proc.c?rev=1906885&r1=1906884&r2=1906885&view=diff
==============================================================================
--- apr/apr/trunk/threadproc/win32/proc.c (original)
+++ apr/apr/trunk/threadproc/win32/proc.c Sat Jan 21 15:52:22 2023
@@ -915,6 +915,21 @@ APR_DECLARE(apr_status_t) apr_proc_creat
SetHandleInformation(GetStdHandle(STD_ERROR_HANDLE),
stderr_reset, stderr_reset);
}
+
+ /* Close our side of pipes before releasing lock: otherwise they
+ * could like to other process when apr_proc_create() is used from
+ * from multiple threads.
+ */
+ if ((attr->child_in) && (attr->child_in != &no_file)) {
+ apr_file_close(attr->child_in);
+ }
+ if ((attr->child_out) && (attr->child_out != &no_file)) {
+ apr_file_close(attr->child_out);
+ }
+ if ((attr->child_err) && (attr->child_err != &no_file)) {
+ apr_file_close(attr->child_err);
+ }
+
/* RELEASE CRITICAL SECTION
* The state of the inherited handles has been restored.
*/
@@ -933,15 +948,6 @@ APR_DECLARE(apr_status_t) apr_proc_creat
new->hproc = pi.hProcess;
new->pid = pi.dwProcessId;
- if ((attr->child_in) && (attr->child_in != &no_file)) {
- apr_file_close(attr->child_in);
- }
- if ((attr->child_out) && (attr->child_out != &no_file)) {
- apr_file_close(attr->child_out);
- }
- if ((attr->child_err) && (attr->child_err != &no_file)) {
- apr_file_close(attr->child_err);
- }
CloseHandle(pi.hThread);
return APR_SUCCESS;