Hi all,

I am seeing crashes in my daemon when I use dispatch_async() in a for(;;)
loop.

Crashed Thread:  8  Dispatch queue: com.apple.CFURLCACHE_work_queue
Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: EXC_I386_GPFLT

*Background*

My daemon processes url's and in one of the function I have to check
against server for evaluation. The crash is happening after url's are sent
to the server and getting the response successfully. After analysis of the
crash log I do see that CFRelease is called and is crashing after that. I
am trying to use GCD for the first time and any help will be appreciated.
Below is my code snippet,

*- (void)sendRequest: (NSString *) urlRequest*

{

    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init]
autorelease];

    [request setURL:[NSURL URLWithString:urlString]];

    [request setHTTPMethod:@"GET"];

    NSHTTPURLResponse * response;

    NSError * error = NULL;

    NSData* data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error];

     if ([data length] >0 && error == nil && [response statusCode] == 200)

    {

        NSError *error;

        NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data
options:0 error:&error];

        NSLog(@"New Verify.Json Dict: %@", jsonDict);

      }

}

*-(void) process_URL_request()*
{
      // do small process to get NSString* url and pass the URL to
sendRequest() fuction.

     dispatch_queue_t queue = dispatch_get_global_queue(
DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

     dispatch_async(queue, ^{

             [self sendRequest:url];

     });
}

int main()
{

for(;;) {

     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

       *process_URL_request();*

     [pool release];

     }

}


*Below is an excerpt from the crash log*

Thread 8 Crashed:: Dispatch queue: com.apple.CFURLCACHE_work_queue

0   libobjc.A.dylib               0x00007fff91bf9750 objc_msgSend_vtable14
+ 16

1   com.apple.CoreFoundation       0x00007fff917d728a CFRelease + 170

2   com.apple.CFNetwork           0x00007fff89dae766
__CFURLCacheNode::~__CFURLCacheNode() + 84

3   com.apple.CFNetwork           0x00007fff89dae703
__CFURLCacheNode::~__CFURLCacheNode() + 17

4   com.apple.CFNetwork           0x00007fff89dacd1e
ProcessCacheTasks(__CFURLCache*, bool) + 433

5   com.apple.CFNetwork           0x00007fff89dac69c
_CFURLCacheTimerCallback(void*) + 484

6   libdispatch.dylib             0x00007fff915700b6
_dispatch_client_callout + 8

7   libdispatch.dylib             0x00007fff9157229b
_dispatch_source_invoke + 691

8   libdispatch.dylib             0x00007fff91571305 _dispatch_queue_invoke
+ 72

9   libdispatch.dylib             0x00007fff91571448 _dispatch_queue_drain
+ 180

10  libdispatch.dylib             0x00007fff915712f1 _dispatch_queue_invoke
+ 52

11  libdispatch.dylib             0x00007fff915711c3
_dispatch_worker_thread2 + 249

12  libsystem_c.dylib             0x00007fff8bc05cdb _pthread_wqthread + 404

13  libsystem_c.dylib             0x00007fff8bbf0191 start_wqthread + 13



thanks,
~PR
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to