@@ -100,8 +100,8 @@ template <int KIND> struct FitsInIntegerKind {
100
100
101
101
// If a condition occurs that would assign a nonzero value to CMDSTAT but
102
102
// the CMDSTAT variable is not present, error termination is initiated.
103
- int TerminationCheck (int status, const Descriptor *cmdstat, const Descriptor *cmdmsg,
104
- Terminator &terminator) {
103
+ int TerminationCheck (int status, const Descriptor *cmdstat,
104
+ const Descriptor *cmdmsg, Terminator &terminator) {
105
105
if (status == -1 ) {
106
106
if (!cmdstat) {
107
107
terminator.Crash (" Execution error with system status code: %d" , status);
@@ -191,8 +191,7 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
191
191
if (wait) {
192
192
// either wait is not specified or wait is true: synchronous mode
193
193
int status{std::system (newCmd)};
194
- int exitStatusVal{
195
- TerminationCheck (status, cmdstat, cmdmsg, terminator)};
194
+ int exitStatusVal{TerminationCheck (status, cmdstat, cmdmsg, terminator)};
196
195
CheckAndStoreIntToDescriptor (exitstat, exitStatusVal, terminator);
197
196
} else {
198
197
// Asynchronous mode
@@ -204,26 +203,27 @@ void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
204
203
ZeroMemory (&pi, sizeof (pi));
205
204
206
205
// append "cmd.exe /c " to the beginning of command
207
- const char *cmd{command->OffsetElement ()};
208
206
const char *prefix{" cmd.exe /c " };
209
- char *newCmd{(char *)malloc (std::strlen (prefix) + std::strlen (cmd) + 1 )};
207
+ char *newCmdWin{
208
+ (char *)malloc (std::strlen (prefix) + std::strlen (newCmd) + 1 )};
210
209
if (newCmd != NULL ) {
211
- std::strcpy (newCmd , prefix);
212
- std::strcat (newCmd, cmd );
210
+ std::strcpy (newCmdWin , prefix);
211
+ std::strcat (newCmdWin, newCmd );
213
212
} else {
214
213
terminator.Crash (" Memory allocation failed for newCmd" );
215
214
}
216
215
217
216
// Convert the char to wide char
218
- const size_t sizeNeeded{mbstowcs (NULL , newCmd , 0 ) + 1 };
217
+ const size_t sizeNeeded{mbstowcs (NULL , newCmdWin , 0 ) + 1 };
219
218
wchar_t *wcmd{new wchar_t [sizeNeeded]};
220
- if (std::mbstowcs (wcmd, newCmd , sizeNeeded) == static_cast <size_t >(-1 )) {
219
+ if (std::mbstowcs (wcmd, newCmdWin , sizeNeeded) == static_cast <size_t >(-1 )) {
221
220
terminator.Crash (" Char to wide char failed for newCmd" );
222
221
}
223
- free (newCmd );
222
+ free (newCmdWin );
224
223
225
224
if (CreateProcess (nullptr , wcmd, nullptr , nullptr , FALSE , 0 , nullptr ,
226
225
nullptr , &si, &pi)) {
226
+ // Close handles so it will be removed when terminated
227
227
CloseHandle (pi.hProcess );
228
228
CloseHandle (pi.hThread );
229
229
} else {
0 commit comments