[banshee] AudioscrobblerConnection: Fix crash during scrobbling (bgo#662122)



commit 82968393848f082296554b4493b9eeb320b66a57
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date:   Sat Mar 17 16:49:25 2012 +0100

    AudioscrobblerConnection: Fix crash during scrobbling (bgo#662122)
    
    If the timeout for BeginGetRequestStream expires while we are already
    writing to the request stream, this causes an exception. Move the
    relevant part of the code inside the existing try/catch block, so that
    this exception gets caught and doesn't lead to a crash.

 .../Lastfm/Lastfm/AudioscrobblerConnection.cs      |   15 ++++++++-------
 1 files changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs b/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs
index 8a48067..9a3ee66 100644
--- a/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs
+++ b/src/Libraries/Lastfm/Lastfm/AudioscrobblerConnection.cs
@@ -274,9 +274,17 @@ namespace Lastfm
         private void TransmitGetRequestStream (IAsyncResult ar)
         {
             Stream stream;
+            TransmitState ts;
 
             try {
                 stream = current_web_req.EndGetRequestStream (ar);
+
+                ts = (TransmitState) ar.AsyncState;
+                StringBuilder sb = ts.StringBuilder;
+
+                StreamWriter writer = new StreamWriter (stream);
+                writer.Write (sb.ToString ());
+                writer.Close ();
             } catch (Exception e) {
                 Log.Exception ("Failed to get the request stream", e);
                 state = State.Idle;
@@ -284,13 +292,6 @@ namespace Lastfm
                 return;
             }
 
-            TransmitState ts = (TransmitState) ar.AsyncState;
-            StringBuilder sb = ts.StringBuilder;
-
-            StreamWriter writer = new StreamWriter (stream);
-            writer.Write (sb.ToString ());
-            writer.Close ();
-
             state = State.WaitingForResponse;
             current_async_result = current_web_req.BeginGetResponse (TransmitGetResponse, ts);
             if (current_async_result == null) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]