[host] windows: fix stdout/stderr resource leak

This commit is contained in:
Geoffrey McRae 2023-11-12 06:20:29 +11:00
parent cd6485f2ed
commit 7321ca6768

View File

@ -66,6 +66,9 @@ struct AppState
HANDLE exitWait; HANDLE exitWait;
HANDLE taskHandle; HANDLE taskHandle;
FILE * stdErrFile;
FILE * stdOutFile;
_Atomic(bool) hasPendingActivationRequest; _Atomic(bool) hasPendingActivationRequest;
}; };
@ -349,10 +352,16 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
int std_out_fd = _open_osfhandle((intptr_t)std_out, _O_TEXT); int std_out_fd = _open_osfhandle((intptr_t)std_out, _O_TEXT);
if (std_err_fd > 0) if (std_err_fd > 0)
*stderr = *_fdopen(std_err_fd, "w"); {
app.stdErrFile = _fdopen(std_err_fd, "w");
*stderr = *app.stdErrFile;
}
if (std_out_fd > 0) if (std_out_fd > 0)
*stdout = *_fdopen(std_out_fd, "w"); {
app.stdOutFile = _fdopen(std_out_fd, "w");
*stdout = *app.stdOutFile;
}
} }
int result = 0; int result = 0;
@ -474,6 +483,12 @@ finish:
if (app.taskHandle) if (app.taskHandle)
AvRevertMmThreadCharacteristics(app.taskHandle); AvRevertMmThreadCharacteristics(app.taskHandle);
if (app.stdErrFile)
fclose(app.stdErrFile);
if (app.stdOutFile)
fclose(app.stdOutFile);
return result; return result;
} }