Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7188

iOS 14 crash zombie when use dispatch_semaphore

$
0
0

I handle some old code, it runs well, but now crash only on ios 14

here is the demo

static NSData *DownloadWithRange(NSURL *URL, NSError *__autoreleasing *error) {    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:URL];    request.timeoutInterval = 10.0;    __block NSData *data = nil;    __block dispatch_semaphore_t sema = dispatch_semaphore_create(0);    NSURLSessionConfiguration *config = NSURLSessionConfiguration.ephemeralSessionConfiguration;    NSURLSession *URLSession = [NSURLSession sessionWithConfiguration:config];    NSURLSessionDataTask *task = [URLSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable taskData, NSURLResponse * _Nullable response, NSError * _Nullable taskError) {        data = taskData;        if (error)            *error = taskError;        dispatch_semaphore_signal(sema);    }];    [task resume];    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);    return data;}- (IBAction)crashButton:(id)sender {    NSURL *url  = [NSURL URLWithString:@"http://error"];    NSError * error = nil;    NSData *compressedData = DownloadWithRange(url, &error);    NSLog(@"error is %@",error);}

before DownloadWithRange returned, the taskError memory(NSURLError) has released

on ios 13, it don't crash

it's really weird


Viewing all articles
Browse latest Browse all 7188

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>