Skip to content

Commit

Permalink
Fix crash in SafePipeHandle.ReleaseHandle() on Windows (mono#3797)
Browse files Browse the repository at this point in the history
The ReleaseHandle() methods tries to deallocate the handle as if it was a
pointer to heap memory. But on Windows it's a HANDLE. The call to
Marshal.FreeHGlobal() causes a crash on Windows. It doesn't crash on other
platforms probably due to the emulated handles which are indeed heap allocated
memory objects. But the underlying file descriptor is never closed so there
should be a file descriptor leak on other platforms.

This patch fixes the issue by calling MonoIO.Close() on the handle rather than
Marshal.FreeHGlobal()
  • Loading branch information
ntherning authored and mderoy committed Jan 24, 2018
1 parent cb14ed6 commit 7e3d6f8
Showing 1 changed file with 2 additions and 6 deletions.
Expand Up @@ -46,12 +46,8 @@ public SafePipeHandle (IntPtr preexistingHandle, bool ownsHandle)

protected override bool ReleaseHandle ()
{
try {
Marshal.FreeHGlobal (handle);
return true;
} catch (ArgumentException) {
return false;
}
MonoIOError error;
return MonoIO.Close (handle, out error);
}
}
}
Expand Down

0 comments on commit 7e3d6f8

Please sign in to comment.