Permalink
Browse files

Backport of r158326

svn path=/branches/mono-2-6/xsp/; revision=158327
  • Loading branch information...
grendello committed Jun 2, 2010
1 parent a8ba8f6 commit f01ef84b16ea0d9874d5b5aadbba23ebffd4421a
Showing with 29 additions and 2 deletions.
  1. +10 −0 ChangeLog
  2. +8 −1 src/Mono.WebServer.Apache/ModMonoWorkerRequest.cs
  3. +11 −1 src/Mono.WebServer/XSPWorkerRequest.cs
View
@@ -1,3 +1,13 @@
+2010-06-02 Marek Habersack <mhabersack@novell.com>
+
+ * src/Mono.WebServer/XSPWorkerRequest.cs: avoid double handle close when sending
+ response from a file in certain cases.
+
+2010-06-02 Marek Habersack <mhabersack@novell.com>
+
+ * src/Mono.WebServer.Apache/ModMonoWorkerRequest.cs: avoid double handle close when sending
+ response from a file in certain cases.
+
2010-05-28 Marek Habersack <mhabersack@novell.com>
* src/Mono.WebServer/ApplicationServer.cs: OnAccept sends BeginAccept exceptions back
@@ -599,7 +599,14 @@ public override void SendResponseFromFile (string filename, long offset, long le
FileStream file = null;
try {
file = File.OpenRead (filename);
- base.SendResponseFromFile (file.Handle, offset, length);
+ // We must not call the SendResponseFromFile overload which
+ // takes IntPtr in this case since it will callthe base
+ // implementation of that overload which, in turn, will
+ // close the handle (as it uses FileStream to wrap the
+ // handle we pass). This will cause the handle to be closed
+ // twice (FileStream owns the handle). So we just take a
+ // shortcut to what the base overload does here.
+ SendFromStream (file, offset, length);
} finally {
if (file != null)
file.Close ();
@@ -736,7 +736,17 @@ public override bool IsSecure ()
public override void SendResponseFromFile (string filename, long offset, long length)
{
using (FileStream fs = File.OpenRead (filename)) {
- SendResponseFromFile (fs.Handle, offset, length);
+ if (secure || no_libc || (tried_sendfile && !use_sendfile)) {
+ // We must not call the SendResponseFromFile overload which
+ // takes IntPtr in this case since it will call the base
+ // implementation of that overload which, in turn, will
+ // close the handle (as it uses FileStream to wrap the
+ // handle we pass). This will cause the handle to be closed
+ // twice (FileStream owns the handle). So we just take a
+ // shortcut to what the base overload does here.
+ SendFromStream (fs, offset, length);
+ } else
+ SendResponseFromFile (fs.Handle, offset, length);
}
}

0 comments on commit f01ef84

Please sign in to comment.