winpty/misc/buffer-tests/Win7Bug_InheritHandles.cc

33 lines
867 B
C++
Raw Normal View History

2015-10-20 04:32:08 +00:00
#include <TestCommon.h>
int main() {
trace("----------------------------------");
Worker p;
p.getStdout().write("<-- origBuffer -->");
auto c = p.child();
auto cb = c.newBuffer(FALSE);
cb.activate();
cb.write("<-- cb -->");
c.dumpConsoleHandles(TRUE);
2015-10-20 04:32:08 +00:00
// Proposed fix: the agent somehow decides it should attach to this
// particular child process. Does that fix the problem?
//
// No, because the child's new buffer was not marked inheritable. If it
// were inheritable, then the parent would "inherit" the handle during
// attach, and both processes would use the same refcount for
// `CloseHandle`.
p.detach();
p.attach(c);
p.dumpConsoleHandles(TRUE);
2015-10-20 04:32:08 +00:00
auto pb = p.openConout();
cb.close();
// Demonstrate that pb is an invalid handle.
pb.close();
Sleep(300000);
}