Fix leaks/undefined behavour in core::run on windows, and remove os::waitpid

This fixes #5976.

It also removes `os::waitpid` in favour of (the existing) `run::waitpid`. I included this change because I figured it is kind of related.

r?