Bug in FileStream.Dispose in Framework 1.1



I have come across a bug in FileStream.Close that causes File handles to leak.

If you create a FileStream then try to write to it when the destination disk
is full:

outputStream.Write(buffer, 0, readCount);

you get an IOException "There is not enough space on the disk".

That's fine, until you then try to dispose the FileStream, by calling
Dispose (or Close, which simply calls Dispose). Dispose attempts to flush
the stream, which causes it to attempt to write the buffer, which generates
an error (since the disk is full), which throws an IOException, leaving the
system file handle unreleased, resulting in a leaked handle.

I've considered obtaining the handle in my catch block and releasing it
directly, but that seems to be a path fraught with peril-- after all, I don't
know what else the FileStream code might do when the object is finalized...

Anyone else seen this? How do I go about reporting it to MS?
.



Relevant Pages

  • Re: Starting on C#...
    ... FileStream is the object that you use for reading/writing a file. ... you would call Dispose() or Close(which calls ... Dispose is a different beast from a Finalizer ... int f ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: App dont stop when closing the form
    ... > Uisng FileStream .. ... I next step i tryed to open this same file to append something to ... I can only tell you that i tryed this fiew times and only thing that ... The correct solution is to call Dispose ...
    (microsoft.public.dotnet.general)
  • Re: File performance
    ... but the main problem is that although I call dispose on the ... filestream, and I expect the garbage handle will not run immediatly, the ... It doesn't give any out of memory ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Writing Byte Array to Disk
    ... byte array to the screen, but I need to write the contents ... to disk. ... Use a FileStream, ... OOC, what would the difference between that and File.WriteAllBytesbe? ...
    (microsoft.public.dotnet.languages.csharp)
  • Too many pending asynchronous disk write causes spurious errors
    ... I am using the asynchronous I/O model to receive data over a socket, and asynchronously write the incoming data to a disk file using FileStream. ... 07:42:50.14 at System.Buffer.InternalBlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, Int32 count) ...
    (microsoft.public.dotnet.framework)