On Sun, Nov 6, 2016 at 9:38 PM, Gavin Lambert
* On Windows, if you desire to pass any file handles at all to the new child process, it is completely whimsical what *other* open file handles you may inadvertently pass -- unless you play games with STARTUPINFOEXA and PROC_THREAD_ATTRIBUTE_LIST to enumerate exactly the set of handles you intend to pass.
FWIW, a slight saving grace with that is that it's most common to open files using NULL security attributes, which makes the file non-inherited by default.
I believe the std::ifstream implementation from Visual Studio 2013 -- the API you use in portable C++ code -- opens files as inheritable by default. Moreover, this API gives you no opportunity to change their inheritability.
You can also flip any existing handle to non-inherited whenever you want.
If your application uses third-party libraries, you have no way to enumerate the complete set of handles held open by your process.