The dispose pattern docs should not use an IntPtr.Zero
handle
#44201
Labels
⌚ Not Triaged
Not triaged
IntPtr.Zero
handle
#44201
Describe the issue or suggestion
The following doc was likely created in .NET Framework times, where the
BaseClassWithSafeHandle
code example creates and closes anIntPTr.Zero
handle, which is NOP on Windows: https://learn.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-dispose#implement-the-dispose-patternThe problem is that on Unix
FD 0
corresponds tostdnin
which means that disposingBaseClassWithSafeHandle
will close the standard input. What's even worse, that it will free upFD 0
for usage in other places, eg.Socket
meaning that creating and disposingBaseClassWithSafeHandle
several times may close the handle under an existing socket leading to unwanted side effects.There were cases where users left the dummy code from the sample in their codebase, eventually leading to hard-to-diagnose production errors, see dotnet/runtime#56750, dotnet/runtime#64305, fabian-blum/AspNetCore.Identity.LiteDB#14.
We should change this example.
The text was updated successfully, but these errors were encountered: