Skip to content

Commit efad06f

Browse files
committed
__unsafe_unretained does not prevent self retain-cycles when not under ARC
1 parent 811e45a commit efad06f

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

CGDWebServer/GCDWebServer.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,11 @@ - (GCDWebServerResponse*)_responseWithContentsOfDirectory:(NSString*)path {
663663

664664
- (void)addGETHandlerForBasePath:(NSString*)basePath directoryPath:(NSString*)directoryPath indexFilename:(NSString*)indexFilename cacheAge:(NSUInteger)cacheAge allowRangeRequests:(BOOL)allowRangeRequests {
665665
if ([basePath hasPrefix:@"/"] && [basePath hasSuffix:@"/"]) {
666+
#if __has_feature(objc_arc)
666667
GCDWebServer* __unsafe_unretained server = self;
668+
#else
669+
__block GCDWebServer* server = self;
670+
#endif
667671
[self addHandlerWithMatchBlock:^GCDWebServerRequest *(NSString* requestMethod, NSURL* requestURL, NSDictionary* requestHeaders, NSString* urlPath, NSDictionary* urlQuery) {
668672

669673
if (![requestMethod isEqualToString:@"GET"]) {

GCDWebDAVServer/GCDWebDAVServer.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,11 @@ @implementation GCDWebDAVServer
561561
- (instancetype)initWithUploadDirectory:(NSString*)path {
562562
if ((self = [super init])) {
563563
_uploadDirectory = [[path stringByStandardizingPath] copy];
564+
#if __has_feature(objc_arc)
564565
GCDWebDAVServer* __unsafe_unretained server = self;
566+
#else
567+
__block GCDWebDAVServer* server = self;
568+
#endif
565569

566570
// 9.1 PROPFIND method
567571
[self addDefaultHandlerForMethod:@"PROPFIND" requestClass:[GCDWebServerDataRequest class] processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {

GCDWebUploader/GCDWebUploader.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,11 @@ - (instancetype)initWithUploadDirectory:(NSString*)path {
277277
return nil;
278278
}
279279
_uploadDirectory = [[path stringByStandardizingPath] copy];
280+
#if __has_feature(objc_arc)
280281
GCDWebUploader* __unsafe_unretained server = self;
282+
#else
283+
__block GCDWebUploader* server = self;
284+
#endif
281285

282286
// Resource files
283287
[self addGETHandlerForBasePath:@"/" directoryPath:[siteBundle resourcePath] indexFilename:nil cacheAge:3600 allowRangeRequests:NO];

0 commit comments

Comments
 (0)