Permalink
Browse files

Fixes #90 - GCM Memory Leak

  • Loading branch information...
1 parent 2ca71d7 commit aff2a56dc0f124ee2c20661d693d773ac95a3b93 @Redth committed Jan 30, 2013
Showing with 53 additions and 47 deletions.
  1. +53 −47 PushSharp.Android/Gcm/GcmMessageTransportAsync.cs
@@ -229,58 +229,64 @@ void processResponseOk(GcmAsyncParameters asyncParam)
void processResponseError(GcmAsyncParameters asyncParam)
{
- var result = new GcmMessageTransportResponse();
- result.ResponseCode = GcmMessageTransportResponseCode.Error;
+ try
+ {
+ var result = new GcmMessageTransportResponse();
+ result.ResponseCode = GcmMessageTransportResponseCode.Error;
- if (asyncParam == null || asyncParam.WebResponse == null)
- throw new GcmMessageTransportException("Unknown Transport Error", result);
+ if (asyncParam == null || asyncParam.WebResponse == null)
+ throw new GcmMessageTransportException("Unknown Transport Error", result);
- if (asyncParam.WebResponse.StatusCode == HttpStatusCode.Unauthorized)
- {
- //401 bad auth token
- result.ResponseCode = GcmMessageTransportResponseCode.InvalidAuthToken;
- throw new GcmAuthenticationErrorTransportException(result);
+ if (asyncParam.WebResponse.StatusCode == HttpStatusCode.Unauthorized)
+ {
+ //401 bad auth token
+ result.ResponseCode = GcmMessageTransportResponseCode.InvalidAuthToken;
+ throw new GcmAuthenticationErrorTransportException(result);
+ }
+ else if (asyncParam.WebResponse.StatusCode == HttpStatusCode.BadRequest)
+ {
+ result.ResponseCode = GcmMessageTransportResponseCode.BadRequest;
+ throw new GcmBadRequestTransportException(result);
+ }
+ else if (asyncParam.WebResponse.StatusCode == HttpStatusCode.InternalServerError)
+ {
+ result.ResponseCode = GcmMessageTransportResponseCode.InternalServiceError;
+ throw new GcmMessageTransportException("Internal Service Error", result);
+ }
+ else if (asyncParam.WebResponse.StatusCode == HttpStatusCode.ServiceUnavailable)
+ {
+ //First try grabbing the retry-after header and parsing it.
+ TimeSpan retryAfter = new TimeSpan(0, 0, 120);
+
+ var wrRetryAfter = asyncParam.WebResponse.GetResponseHeader("Retry-After");
+
+ if (!string.IsNullOrEmpty(wrRetryAfter))
+ {
+ DateTime wrRetryAfterDate = DateTime.UtcNow;
+
+ if (DateTime.TryParse(wrRetryAfter, out wrRetryAfterDate))
+ retryAfter = wrRetryAfterDate - DateTime.UtcNow;
+ else
+ {
+ int wrRetryAfterSeconds = 120;
+ if (int.TryParse(wrRetryAfter, out wrRetryAfterSeconds))
+ retryAfter = new TimeSpan(0, 0, wrRetryAfterSeconds);
+ }
+ }
+
+ //503 exponential backoff, get retry-after header
+ result.ResponseCode = GcmMessageTransportResponseCode.ServiceUnavailable;
+
+ throw new GcmServiceUnavailableTransportException(retryAfter, result);
+ }
+
+ throw new GcmMessageTransportException("Unknown Transport Error", result);
}
- else if (asyncParam.WebResponse.StatusCode == HttpStatusCode.BadRequest)
+ finally
{
- result.ResponseCode = GcmMessageTransportResponseCode.BadRequest;
- throw new GcmBadRequestTransportException(result);
+ if (asyncParam != null && asyncParam.WebResponse != null)
+ asyncParam.WebResponse.Close();
}
- else if (asyncParam.WebResponse.StatusCode == HttpStatusCode.InternalServerError)
- {
- result.ResponseCode = GcmMessageTransportResponseCode.InternalServiceError;
- throw new GcmMessageTransportException("Internal Service Error", result);
- }
- else if (asyncParam.WebResponse.StatusCode == HttpStatusCode.ServiceUnavailable)
- {
- //First try grabbing the retry-after header and parsing it.
- TimeSpan retryAfter = new TimeSpan(0, 0, 120);
-
- var wrRetryAfter = asyncParam.WebResponse.GetResponseHeader("Retry-After");
-
- if (!string.IsNullOrEmpty(wrRetryAfter))
- {
- DateTime wrRetryAfterDate = DateTime.UtcNow;
-
- if (DateTime.TryParse(wrRetryAfter, out wrRetryAfterDate))
- retryAfter = wrRetryAfterDate - DateTime.UtcNow;
- else
- {
- int wrRetryAfterSeconds = 120;
- if (int.TryParse(wrRetryAfter, out wrRetryAfterSeconds))
- retryAfter = new TimeSpan(0, 0, wrRetryAfterSeconds);
- }
- }
-
- //503 exponential backoff, get retry-after header
- result.ResponseCode = GcmMessageTransportResponseCode.ServiceUnavailable;
-
- throw new GcmServiceUnavailableTransportException(retryAfter, result);
- }
-
- asyncParam.WebResponse.Close();
-
- throw new GcmMessageTransportException("Unknown Transport Error", result);
}
class GcmAsyncParameters

0 comments on commit aff2a56

Please sign in to comment.