Browse Source

2010-02-15 Gonzalo Paniagua Javier <[email protected]>

	* StreamWriter.cs:
	* FileStream.cs: if flushing fails when disposing the stream, make
	sure it is closed before throwing the exception. Fixes bug #579146.


svn path=/trunk/mcs/; revision=151761
Gonzalo Paniagua Javier 16 years ago
parent
commit
21350653cc

+ 6 - 0
mcs/class/corlib/System.IO/ChangeLog

@@ -1,3 +1,9 @@
+2010-02-15 Gonzalo Paniagua Javier <[email protected]>
+
+	* StreamWriter.cs:
+	* FileStream.cs: if flushing fails when disposing the stream, make
+	sure it is closed before throwing the exception. Fixes bug #579146.
+
 2010-01-31  Zoltan Varga  <[email protected]>
 
 	* Directory.cs (Exists): Never throw an exception. Fixes #565152.

+ 8 - 1
mcs/class/corlib/System.IO/FileStream.cs

@@ -903,8 +903,13 @@ namespace System.IO
 
 		protected override void Dispose (bool disposing)
 		{
+			Exception exc = null;
 			if (handle != MonoIO.InvalidHandle) {
-				FlushBuffer ();
+				try {
+					FlushBuffer ();
+				} catch (Exception e) {
+					exc = e;
+				}
 
 				if (owner) {
 					MonoIOError error;
@@ -934,6 +939,8 @@ namespace System.IO
 				buf = null;
 				GC.SuppressFinalize (this);
 			}
+			if (exc != null)
+				throw exc;
 		}
 
 #if !NET_2_1

+ 14 - 2
mcs/class/corlib/System.IO/StreamWriter.cs

@@ -152,16 +152,28 @@ namespace System.IO {
 
 		protected override void Dispose (bool disposing) 
 		{
+			Exception exc = null;
 			if (!DisposedAlready && disposing && internalStream != null) {
-				Flush();
+				try {
+					Flush();
+				} catch (Exception e) {
+					exc = e;
+				}
 				DisposedAlready = true;
-				internalStream.Close ();
+				try {
+					internalStream.Close ();
+				} catch (Exception e) {
+					if (exc == null)
+						exc = e;
+				}
 			}
 
 			internalStream = null;
 			byte_buf = null;
 			internalEncoding = null;
 			decode_buf = null;
+			if (exc != null)
+				throw exc;
 		}
 
 		public override void Flush ()