Close p->mwf.fd only if necessary

Found by inspecting crashes in TortoiseGit