From 90a6e2b425d64a7c8a703f68fea10688b108e1d5 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 9 Sep 2021 10:25:45 +0100 Subject: [PATCH] Specify file handles as explicitly non-inheriting on windows * We never want to inherit these, and e.g. Qt process launches are hardcoded to always inherit handles so these need to be excluded so files don't stay open. --- renderdoc/os/win32/win32_stringio.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/renderdoc/os/win32/win32_stringio.cpp b/renderdoc/os/win32/win32_stringio.cpp index 576f13acf..4b65f8f7c 100644 --- a/renderdoc/os/win32/win32_stringio.cpp +++ b/renderdoc/os/win32/win32_stringio.cpp @@ -592,6 +592,15 @@ FILE *fopen(const rdcstr &filename, FileMode mode) FILE *ret = NULL; ::_wfopen_s(&ret, wfn.c_str(), modeString[mode]); + + // specify the handle as non-inheriting + if(ret) + { + int fd = ::_fileno(ret); + HANDLE h = (HANDLE)::_get_osfhandle(fd); + SetHandleInformation(h, HANDLE_FLAG_INHERIT, 0); + } + return ret; } @@ -659,8 +668,14 @@ int fclose(FILE *f) LogFileHandle *logfile_open(const rdcstr &filename) { rdcwstr wfn = StringFormat::UTF82Wide(filename); + + // specify the handle as non-inheriting + SECURITY_ATTRIBUTES security = {}; + security.nLength = sizeof(security); + security.bInheritHandle = FALSE; + return (LogFileHandle *)CreateFileW(wfn.c_str(), FILE_APPEND_DATA, - FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, + FILE_SHARE_READ | FILE_SHARE_WRITE, &security, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); }