Leaks in passing the request using URL at NSString, Objective-C.

Posted by Madan Mohan on Stack Overflow See other posts from Stack Overflow or by Madan Mohan
Published on 2010-06-14T10:03:25Z Indexed on 2010/06/14 10:12 UTC
Read the original article Hit count: 222

Hi Guys, I getting the leak in this method even the allocated nsstring is released.

-(BOOL)getTicket:(NSString*)userName passWord:(NSString*)aPassword isLogin:(BOOL)isLogin
{
login =[self getloginList];
username = login.name;
password = login.password;
NSString* str=@"";
if (isLogin == YES)
{
    str = @"https://accounts.=true&LOGIN_ID=";
    str = [str stringByAppendingString:[self _encodeString:username]];
    str = [str stringByAppendingString:@"&PASSWORD="];
    str = [str stringByAppendingString:[self _encodeString:password]];
}
else if (isLogin == NO) 
{

    str = @"https://accounts.=true&LOGIN_ID=";
    str = [str stringByAppendingString:[self _encodeString:userName]];
    str = [str stringByAppendingString:@"&PASSWORD="];
    str = [str stringByAppendingString: [self _encodeString:aPassword]];
}

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:str] 
                                                       cachePolicy:NSURLRequestReloadIgnoringCacheData 
                                                   timeoutInterval:25.0];
[request setHTTPMethod: @"POST"];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];//****************** i am getting leak here showing as nsstring is leaking
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
printf("\n returnString in getticket:%s",[returnString UTF8String]);

NSRange textRange;

textRange =[returnString rangeOfString:@"TICKET"];

if(textRange.location != NSNotFound)
{
    printf("\n **********************");

    NSArray*  splitValues = [returnString componentsSeparatedByString:@"TICKET="];
    NSString* str1 = [splitValues objectAtIndex:1];
    NSArray* splitValues1 = [str1 componentsSeparatedByString:@"RESULT"];
    NSString* ticket1 = [splitValues1 objectAtIndex:0];
    self.ticket = ticket1;
    self.isCorrectLogin = YES;
    [returnString release];
    return YES;
}
else
{
    self.isCorrectLogin = NO;
    [returnString release];
    return NO;
}

return NO;
}

Please help me out of this problem.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about memory-leaks