text: Q:
  
  EXC_BAD_ACCESS in call to CFSocketSendData
  
  I am using an instance of the this class to pass necessary values to a function for sending Socket Data:
  @interface SsdpParameters : NSObject
  {
      CFDataRef msg;
      CFDataRef addr;
      CFSocketRef sock;
  }
  
  @property CFDataRef msg;
  @property CFDataRef addr;
  @property CFSocketRef sock;
  
  @end
  
  This is the function that is responsible for sending the socket data:
  -(void)SendSsdpResponse:(id)parameters
  {
      SsdpParameters *params = parameters;
      CFDataRef msg = (CFDataRef)params.msg;
      CFDataRef addr = (CFDataRef)params.addr;
      CFSocketRef sock = (CFSocketRef)params.sock;
  
      CFSocketError err = CFSocketSendData (sock, addr, msg, 0);  // Program received signal:  "EXC_BAD_ACCESS".
  
      if (err)
      {
          NSLog(@"Error sending Valid Response");
      }
  }
  
  This function sets up the socket and calls SendSsdpResponse after a 1 second delay:
  - (void) sendValidResponses
  {
      NSMutableString *message = nil;
  CFSocketRef sock = [self newSSDPSendSocket];
  if(sock != nil)
      {
          struct sockaddr_in SSDPaddr;
          memset(&SSDPaddr, 0, sizeof(SSDPaddr));
          SSDPaddr.sin_family=AF_INET;
          SSDPaddr.sin_addr.s_addr=inet_addr(SSDP_ADDRESS);
          SSDPaddr.sin_port=htons(SSDP_PORT);
  
          // Loop through list, sending SSDP
          for (NSString *aKey in list)
          {
              message = [[NSMutableString alloc] initWithString:@"NOTIFY * HTTP/1.1\r\n"];
  
          // Append more lines to message.
  
              CFDataRef addr = CFDataCreate(NULL, (const UInt8*)&SSDPaddr, sizeof(SSDPaddr));
              CFDataRef msg  = CFDataCreate(NULL, (const UInt8*)[message UTF8String], [message lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
  
              SsdpParameters *parameters = [[SsdpParameters alloc] init];
              parameters.msg = msg;
              parameters.addr = addr;
              parameters.sock = sock;
  
              [self performSelector:@selector(SendSsdpResponse:) withObject:parameters afterDelay:1.0];
  
              CFRelease(addr);
              CFRelease(msg);
              [message release];
          }
  
          CFRelease(sock);
      }
  }
  
  As you can see by the comment, in SendSsdpResponse, I an getting a "EXC_BAD_ACCESS" error when trying to call CFSendSocketData.  I have a suspicion that it's because I am "passing" sock, addr, and msg and there is something the runtime does not like about this.  I have run into this problem before with passing variables of the CF data types to other functions.  I have yet to find an answer and hope someone here can finally help me understand what's going on behind the scenes.
  Thanks!
  
  A:
  
  EXC_BAD_ACCESS errors generally indicate that you're attempting to invoke a method on an instance that has already been deallocated. This is often the case when you fail to properly retain variables, especially when they're being passed between functions.
  When you perform the selector with the delay, on this line:
  [self performSelector:@selector(SendSsdpResponse:) withObject:parameters afterDelay:1.0];
  
  You're providing the method with the parameters variable, which has the properties as defined in the header you provided. The problem is that right after the performSelector: method, you're releasing the memory referred to addr and msg. Since you're performing this selector with a delay, the memory that addr and msg point to is being deallocated prior to its use.
  So, once this memory has been released, it is no longer "good" in the SsdpParameters object. You should (in the setter for these properties, on the SsdpParameters object) copy this memory, so that the original callers can release it safely.
  You should investigate this function:
  CFDataRef CFDataCreateCopy (
     CFAllocatorRef allocator,
     CFDataRef theData
  );
  
  Then, your setter could look like:
  @implementation SsdpParameters
  
  ...
  
  - (void)setMsg:(CFDataRef)m {
      // You should also release msg if it already exists
      msg = CFDataCreateCopy(CFAllocatorGetDefault(), m);
  }
  
  ...
  
  @end
  
  