Skip to content

Commit e0a051b

Browse files
committed
Free memory just before returning from proc_open
Setting these pointers to NULL after freeing them was necessary because if an error occurred later on, they could be double-freed after 'goto exit_fail'. It is simpler to free them after all possible sources of error are past.
1 parent e903818 commit e0a051b

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

ext/standard/proc_open.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,13 +1019,6 @@ PHP_FUNCTION(proc_open)
10191019
newprocok = CreateProcessW(NULL, cmdw, &php_proc_open_security, &php_proc_open_security,
10201020
TRUE, dwCreateFlags, envpw, cwdw, &si, &pi);
10211021

1022-
free(cwdw);
1023-
cwdw = NULL;
1024-
free(cmdw);
1025-
cmdw = NULL;
1026-
free(envpw);
1027-
envpw = NULL;
1028-
10291022
if (suppress_errors) {
10301023
SetErrorMode(old_error_mode);
10311024
}
@@ -1187,7 +1180,11 @@ PHP_FUNCTION(proc_open)
11871180
}
11881181
}
11891182

1190-
#ifndef PHP_WIN32
1183+
#ifdef PHP_WIN32
1184+
free(cwdw);
1185+
free(cmdw);
1186+
free(envpw);
1187+
#else
11911188
efree_argv(argv);
11921189
#endif
11931190

0 commit comments

Comments
 (0)