klenin / Spawner

Cross-platform sandbox runner
4 stars 8 forks source link

Don't close std handles #20

Closed rotanov closed 9 years ago

rotanov commented 9 years ago

In buffer.h/cpp there is a output_stdout_buffer_c and input_stdin_buffer_c classes both are derived from handle_buffer_c class and both are setting it's handle to GetStdHandle(...) value.

handle_buffer_c performs CloseHandle in destructor. However multiple invocations of GetStdHandle(...) will return the same value for each std handle type. And it is correct. Which results in double freeing of a resource. Application must close only handles it's created and std handles are not the ones. They must not be closed at all. For details see http://blogs.msdn.com/b/oldnewthing/archive/2013/03/07/10399690.aspx

rotanov commented 9 years ago

I'll fix it with a kludge since current design of buffer classes won't allow for proper fix.