0

I am using GCDAcyncUDPSocket to receive data. In the below code, I am creating a tuple of (timestamp, data) and adding it into another array. Here is my code:

- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data fromAddress:(NSData *)address withFilterContext:(id)filterContext
{
dispatch_queue_t bg_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
NSString *msg = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSTimeInterval t = [self getTime];
if (msg)
{
    [self.activityQueue.activityQueue enqueue:@"1"];
    dispatch_async(bg_queue, ^{
        NSData * d = [data copy];
            [self addRecvJitter:t withData:d];
        d= nil;
    });
}
}

- (void)addRecvJitter:(NSTimeInterval)t withData:(NSData *)data
{

NSString * add = [NSString  stringWithFormat:@"%f",( t - self.jitterOrigin)];
NSArray * addToList = [[NSArray alloc] initWithObjects:add,data, nil];
[_rcvdJitter addObject:addToList];
}

I get the following error malloc: * error for object 0x7a9c2820: double free * set a breakpoint in malloc_error_break to debug at this line"[_rcvdJitter addObject:addToList];"

Can I get some help regarding this?

Thanks

1 Answers1

0

This looks like a threading issue. I'm assuming the didReceiveData is called on the main thread and you are dispatching the work onto another background thread.

Did you try removing d= nil;

Also, the msg is being created using the received data just to be checked if valid, then the data is copied and used again.

What are you trying to achieve?

Regarding the debug helper message, you should add a symbolic breakpoint and set the type to malloc_error_break. Check Vinzzz answer here How to “set a breakpoint in malloc_error_break to debug"

Community
  • 1
  • 1
some_id
  • 29,466
  • 62
  • 182
  • 304