title: EXC_BAD_ACCESS in call to CFSocketSendData
body: <p>I am using an instance of the this class to pass necessary values to a function for sending Socket Data:</p>
  
  <pre><code>@interface SsdpParameters : NSObject
  {
      CFDataRef msg;
      CFDataRef addr;
      CFSocketRef sock;
  }
  
  @property CFDataRef msg;
  @property CFDataRef addr;
  @property CFSocketRef sock;
  
  @end
  </code></pre>
  
  <p>This is the function that is responsible for sending the socket data:</p>
  
  <pre><code>-(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");
      }
  }
  </code></pre>
  
  <p>This function sets up the socket and calls SendSsdpResponse after a 1 second delay:</p>
  
  <pre><code>- (void) sendValidResponses
  {
      NSMutableString *message = nil;
  CFSocketRef sock = [self newSSDPSendSocket];
  if(sock != nil)
      {
          struct sockaddr_in SSDPaddr;
          memset(&amp;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*)&amp;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);
      }
  }
  </code></pre>
  
  <p>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" <code>sock</code>, <code>addr</code>, and <code>msg</code> 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.</p>
  
  <p>Thanks!</p>