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 1022321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:26:53+00:00 2026-05-16T11:26:53+00:00

I am getting a potential leak in these methods..can anyone please help me..Leak in

  • 0

I am getting a potential leak in these methods..can anyone please help me..Leak in method 1 is in line 5..I am referencing this method from another class as [sync loginHandler] where sync is an object of the class which has the method loginHandler..

-(void) loginHandler
{
1   SCRMsugarsoap* service = [[SCRMsugarsoap alloc] initWithUrl:serverURL];
2   service.logging = YES;
3   service.username = userName;
4   service.password = password;
5   [service login:self action:@selector(sessionIdHandler:) user_auth: [[[SCRMuser_auth alloc] initWithUsername:userName andPassword:password]autorelease] application_name: @""];
6   [service release];
}

And another method where I have problems with leaks is

-(NSMutableArray *)searchContacts:(NSString *)tableName bySearchString:(NSString *)searchString
{

1   NSString *sid=@"";
2   NSString *firstname=@"";
3   NSString *lastname=@"";
4   NSString *qsql;
    //NSArray *contactArray=[[NSArray alloc]init];
5   searchArray=[[NSMutableArray alloc]init];

6   qsql=[NSString stringWithFormat:@"SELECT DISTINCT sugar_id,first_name,last_name FROM CONTACTS where last_name LIKE '%%%@%%' OR first_name LIKE '%%%@%%' GROUP BY sugar_id ORDER BY last_name",searchString,searchString];
7   sqlite3_stmt *statement;
8   if (sqlite3_prepare_v2( db, [qsql UTF8String], -1, &statement, nil) == SQLITE_OK) {
9       while (sqlite3_step(statement) == SQLITE_ROW) 
10      {
                //TODO: alloc Contact object
11          Contact *contacts=[[Contact alloc]init];

12          sid = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 0)];
13          firstname = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 1)];
14          lastname = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement, 2)];
15

16          if ([firstname isEqualToString:@"(null)"]) {
                lastname=[lastname stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[lastname substringToIndex:1] uppercaseString]];
17              contacts.lastName=lastname;
18              contacts.sugarId=sid;
19              contacts.firstName=@"";


                }
20          else {

21              firstname=[firstname stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[firstname substringToIndex:1] uppercaseString]];
22              lastname=[lastname stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[lastname substringToIndex:1] uppercaseString]];
23              contacts.firstName=firstname;
24              contacts.lastName=lastname;
25              contacts.sugarId=sid;


            }
26          [searchArray addObject:contacts];
            //searchArray=[NSMutableArray arrayWithObjects:contacts];           
            //TODO:  Release contacts variable
27          [contacts release];
28          [sid release]; //not sure about releasing these objects..just gave a try
29          [firstname release];
30          [lastname release];
31          firstname = nil;
32          lastname = nil;
33          sid=nil;


        }       
34      sqlite3_reset(statement);


    }

35  sqlite3_finalize(statement);
36  return searchArray; 
}

I am releasing searchArray in dealloc method. The leaks are between lines 5,11-14,16,21,22.These lines vary whenever I try to fiddle with the code..please help me guys..waiting for your suggestions..

I tried using instruments and these are the areas figured out using it..Can I also use build and analyze in xcode..I used that and made some changes to the code..

EDIT (Added methods that code 1 refers)

- (id) initWithUsername: (NSString*) username andPassword: (NSString*) pass 
    {
        if(self = [super init])
        {
            Soap *converter = [[Soap alloc] init];
            SCRMsugarsoap *service = [[SCRMsugarsoap alloc] init];

            [service get_server_version:self action:@selector(get_server_versionHandler:)];

            self.user_name = username;
            self.password = [converter tomd5:pass];

            [converter release];
            [service release];
        }
        return self;
    }

-(NSString*)tomd5:(NSString*)value{
    const char *cStr = [value UTF8String];
    unsigned char result[CC_MD5_DIGEST_LENGTH];
    CC_MD5(cStr, strlen(cStr), result);
    return [NSString stringWithFormat: @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
            result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7],
            result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15]
    ];
}
  • 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-16T11:26:54+00:00Added an answer on May 16, 2026 at 11:26 am

    If searchArray is an instance variable, and you call searchContacts more than once, you will leak the previous value stored in searchArray.

    You need to do something like…

    [searchArray release];
    searchArray=[[NSMutableArray alloc] init];
    

    Sending messages to nil objects has no effect, so if searchArray hasn’t been set, calling release will do nothing. On subsequent calls, you will release search array before letting go of the pointer to it.

    Edit: Also, you are over releasing sid, firstName and lastName. Objects returned by class convenience methods like that are almost always returned autoreleased. Take a look at the Memory Management Guide

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

Sidebar

Related Questions

I'm getting a Potential leak message upon doing an Analyze run of this code
Using the distance logic from this SO post , I'm getting back a properly-filtered
Getting the subdomain from a URL sounds easy at first. http://www.domain.example Scan for the
Getting started with NHibernate How can I generate identity fields in nHibernate using Hilo
Getting the above error in following code. How to rectify it. Thanks. Please look
Getting this error: 2009-09-03 12:44:02.307 xcodebuild[307:10b] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler
Getting a rendering error for this form: 'NoneType' object has no attribute 'widget' http://dpaste.com/88585/
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to
Getting Json from the Server and displaying it in the grid is relatively straight
I am getting several 'undefined' errors when running this code in JSHint: MERLIN.namespace('MERLIN.http'); MERLIN.http

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.