Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6873103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:00:55+00:00 2026-05-27T04:00:55+00:00

I am using an instance of the this class to pass necessary values to

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:00:56+00:00Added an answer on May 27, 2026 at 4:00 am

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i load a class using Class.forName(klassname,false,loader) After this i create an instance using klass.newInstance();
Let's say I have this : class whatever(object): def __init__(self): pass and this function:
Using instance methods as callbacks for event handlers changes the scope of this from
For instance is it possible to write this if (variable != null) without using
I want to pass a default argument to an instance method using the value
I have class that extends 'IntentService' - this class occasionally receives data from a
My current application is using an instance based data access layer. I instantiate the
I'm setting up a data model in django using multiple-table inheritance (MTI) like this:
I am using an instance of ManualResetEvent to control thread access to a resource
When you move beyond using one instance for your database, what is the best

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.