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

  • Home
  • SEARCH
  • 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 6319503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:48:58+00:00 2026-05-24T15:48:58+00:00

Currently I’m working on enhancing a project that has been developed by an external

  • 0

Currently I’m working on enhancing a project that has been developed by an external company for us. I’m still in the learning phases of IOS development, so want to make sure that I do things right at the beginning rather than hurt at the end of the project. I’m running Analyze on the project and getting a “Potential leak of an object allocated on line 166 and stored into ‘commandToSend'” from the following block of code.

-(NSData*)GetBusinessCodeBase64:(NSString*)strBusiCode{
    NSArray *tmp_arr = [strBusiCode componentsSeparatedByString:@"-"];
    NSMutableData *commandToSend= [[NSMutableData alloc] init];
    unsigned char whole_byte;
    char byte_chars[3] = {'\0','\0','\0'};
    int i;
    for (i=0; i < [tmp_arr count]; i++) {
        byte_chars[0] = [[tmp_arr objectAtIndex:i] characterAtIndex:0];
        byte_chars[1] = [[tmp_arr objectAtIndex:i] characterAtIndex:1];
        whole_byte = strtol(byte_chars, NULL, 16);
        [commandToSend appendBytes:&whole_byte length:1]; 
    }
    //NSData *result = [NSData dataWithData:commandToSend];
    //[commandToSend release];
    //return result;
    return commandToSend;
}

My investigating of this is that the call to this function wants an NSData* to be returned. So I looked at doing

NSData *result = [NSData dataWithData:commandToSend];
[commandToSend release];
return result;

instead of the direct return of commandToSend.

Is this the correct way of returning NSMutableData objects without leaking or is there some other way that I should be doing this.

  • 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-24T15:48:59+00:00Added an answer on May 24, 2026 at 3:48 pm

    Your solution works if you wish to ensure that an immutable NSData is returned. Alternatively, you could change the definition for commandToSend to:

    NSMutableData *commandToSend = [NSMutableData data];
    ...
    return commandToSend;
    

    I would prefer this solution, it’s less code and perfectly okay as NSMutableData is a subclass of NSData. It’s really up to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, my MVC 3 app has a dependency on a static class that is
Currently I'm learning C++ and I've been trying to create a simple image processing
Currently working on database part of android project. The main aim of the project
Currently working with converting SQLException error messages into messages that are more useful for
Currently I have a UITableview, I have enough data that cannot be shown entirely
Currently, Enum.Parse supports only the comma as the value separator, so that MemberOne,MemberThree will
Currently I am working on small application in asp.net mvc. It is a some
Currently I have alot of information that are in several different divs. I want
Currently, working with RC0 Denali, having some issues I am attempting to review data
currently i am modifying an existing CakePhp project and i'd like to set a

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.