Yeah, calling TerminateProcess with INVALID_HANDLE_VALUE is a stupid idea to start with. I guess the case that was supposed to be solved was that the process might have died without pid.osHandle being updated, but the handle is probably still valid then.