Ben Copsey

Add lock around progress updates and cancel to iphone attempting to access zombie data

@@ -112,6 +112,9 @@ @@ -112,6 +112,9 @@
112 //This lock will block the request until the delegate supplies authentication info 112 //This lock will block the request until the delegate supplies authentication info
113 NSConditionLock *authenticationLock; 113 NSConditionLock *authenticationLock;
114 114
  115 + //This lock prevents the operation from being cancelled while it is trying to update the progress, and vice versa
  116 + NSLock *progressLock;
  117 +
115 //Called on the delegate when the request completes successfully 118 //Called on the delegate when the request completes successfully
116 SEL didFinishSelector; 119 SEL didFinishSelector;
117 120
@@ -85,6 +85,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy @@ -85,6 +85,7 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy
85 [domain release]; 85 [domain release];
86 [authenticationRealm release]; 86 [authenticationRealm release];
87 [url release]; 87 [url release];
  88 + [progressLock release];
88 [authenticationLock release]; 89 [authenticationLock release];
89 [lastActivityTime release]; 90 [lastActivityTime release];
90 [responseCookies release]; 91 [responseCookies release];
@@ -118,6 +119,13 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy @@ -118,6 +119,13 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy
118 return complete; 119 return complete;
119 } 120 }
120 121
  122 +- (void)cancel
  123 +{
  124 + [progressLock lock];
  125 + [super cancel];
  126 + [progressLock unlock];
  127 +}
  128 +
121 - (int)totalBytesRead 129 - (int)totalBytesRead
122 { 130 {
123 return totalBytesRead; 131 return totalBytesRead;
@@ -206,6 +214,9 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy @@ -206,6 +214,9 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy
206 - (void)loadRequest 214 - (void)loadRequest
207 { 215 {
208 CFRunLoopAddCommonMode(CFRunLoopGetCurrent(),ASIHTTPRequestRunMode); 216 CFRunLoopAddCommonMode(CFRunLoopGetCurrent(),ASIHTTPRequestRunMode);
  217 +
  218 + [progressLock release];
  219 + progressLock = [[NSLock alloc] init];
209 220
210 [authenticationLock release]; 221 [authenticationLock release];
211 authenticationLock = [[NSConditionLock alloc] initWithCondition:1]; 222 authenticationLock = [[NSConditionLock alloc] initWithCondition:1];
@@ -321,8 +332,14 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy @@ -321,8 +332,14 @@ static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventTy
321 332
322 - (void)updateProgressIndicators 333 - (void)updateProgressIndicators
323 { 334 {
  335 + [progressLock lock];
  336 + if ([self isCancelled]) {
  337 + [progressLock unlock];
  338 + return;
  339 + }
324 [self updateUploadProgress]; 340 [self updateUploadProgress];
325 [self updateDownloadProgress]; 341 [self updateDownloadProgress];
  342 + [progressLock unlock];
326 343
327 } 344 }
328 345
@@ -30,15 +30,17 @@ @@ -30,15 +30,17 @@
30 <object class="IBUILabel" id="602749642"> 30 <object class="IBUILabel" id="602749642">
31 <reference key="NSNextResponder" ref="191373211"/> 31 <reference key="NSNextResponder" ref="191373211"/>
32 <int key="NSvFlags">292</int> 32 <int key="NSvFlags">292</int>
33 - <string key="NSFrame">{{20, 20}, {280, 105}}</string> 33 + <string key="NSFrame">{{20, 20}, {280, 144}}</string>
34 <reference key="NSSuperview" ref="191373211"/> 34 <reference key="NSSuperview" ref="191373211"/>
35 <bool key="IBUIOpaque">NO</bool> 35 <bool key="IBUIOpaque">NO</bool>
36 <bool key="IBUIClipsSubviews">YES</bool> 36 <bool key="IBUIClipsSubviews">YES</bool>
37 <bool key="IBUIUserInteractionEnabled">NO</bool> 37 <bool key="IBUIUserInteractionEnabled">NO</bool>
38 <string type="base64-UTF8" key="IBUIText">RGVtb25zdHJhdGVzIGZldGNoaW5nIGEgd2ViIHBhZ2Ugc3luY2hyb25vdXNseSwgdGhlIEhUTUwgc291 38 <string type="base64-UTF8" key="IBUIText">RGVtb25zdHJhdGVzIGZldGNoaW5nIGEgd2ViIHBhZ2Ugc3luY2hyb25vdXNseSwgdGhlIEhUTUwgc291
39 cmNlIHdpbGwgYXBwZWFyIGluIHRoZSBib3ggYmVsb3cgd2hlbiB0aGUgZG93bmxvYWQgaXMgY29tcGxl 39 cmNlIHdpbGwgYXBwZWFyIGluIHRoZSBib3ggYmVsb3cgd2hlbiB0aGUgZG93bmxvYWQgaXMgY29tcGxl
40 -dGUuICBJbiByZWFsIHdvcmxkIHNpdHVhdGlvbnMsIHlvdSdkIGJlIG1vcmUgbGlrZWx5IHRvIHJ1biB0 40 +dGUuICBUaGUgaW50ZXJmYWNlIHdpbGwgbG9jayB1cCB3aGVuIHlvdSBwcmVzcyB0aGlzIGJ1dHRvbiB1
41 -aGlzIGluIGEgdGhyZWFkLg</string> 41 +bnRpbCB0aGUgb3BlcmF0aW9uIHRpbWVzIG91dCBvciBzdWNjZWVkcy4gSW4gcmVhbCB3b3JsZCBzaXR1
  42 +YXRpb25zLCB5b3UnZCBiZSBtb3JlIGxpa2VseSB0byB1c2Ugc3luY2hyb25vdXMgcmVxdWVzdHMgaW4g
  43 +YSB0aHJlYWQuA</string>
42 <object class="NSFont" key="IBUIFont" id="467718481"> 44 <object class="NSFont" key="IBUIFont" id="467718481">
43 <string key="NSName">Helvetica</string> 45 <string key="NSName">Helvetica</string>
44 <double key="NSSize">1.400000e+01</double> 46 <double key="NSSize">1.400000e+01</double>
@@ -56,7 +58,7 @@ aGlzIGluIGEgdGhyZWFkLg</string> @@ -56,7 +58,7 @@ aGlzIGluIGEgdGhyZWFkLg</string>
56 <object class="IBUIButton" id="963091686"> 58 <object class="IBUIButton" id="963091686">
57 <reference key="NSNextResponder" ref="191373211"/> 59 <reference key="NSNextResponder" ref="191373211"/>
58 <int key="NSvFlags">292</int> 60 <int key="NSvFlags">292</int>
59 - <string key="NSFrame">{{20, 133}, {72, 37}}</string> 61 + <string key="NSFrame">{{20, 172}, {72, 37}}</string>
60 <reference key="NSSuperview" ref="191373211"/> 62 <reference key="NSSuperview" ref="191373211"/>
61 <bool key="IBUIOpaque">NO</bool> 63 <bool key="IBUIOpaque">NO</bool>
62 <bool key="IBUIClearsContextBeforeDrawing">NO</bool> 64 <bool key="IBUIClearsContextBeforeDrawing">NO</bool>
@@ -84,7 +86,7 @@ aGlzIGluIGEgdGhyZWFkLg</string> @@ -84,7 +86,7 @@ aGlzIGluIGEgdGhyZWFkLg</string>
84 <object class="IBUITextView" id="251778509"> 86 <object class="IBUITextView" id="251778509">
85 <reference key="NSNextResponder" ref="191373211"/> 87 <reference key="NSNextResponder" ref="191373211"/>
86 <int key="NSvFlags">292</int> 88 <int key="NSvFlags">292</int>
87 - <string key="NSFrame">{{20, 184}, {280, 187}}</string> 89 + <string key="NSFrame">{{20, 217}, {280, 154}}</string>
88 <reference key="NSSuperview" ref="191373211"/> 90 <reference key="NSSuperview" ref="191373211"/>
89 <bool key="IBUIOpaque">NO</bool> 91 <bool key="IBUIOpaque">NO</bool>
90 <bool key="IBUIClipsSubviews">YES</bool> 92 <bool key="IBUIClipsSubviews">YES</bool>