views:

46

answers:

0

Hi,

I am getting random malloc crashes in stringByReplacingOccurrencesOfString. I've noticed that it crashes on longer strings, but I can't seem to find why. What could be the problem?

The error:

CashTrader(53448,0xb0103000) malloc: *** error for object 0x5c5eca0: incorrect checksum for freed object - object was probably modified after being freed.

Input encryptedparams

raStwjnw9uiOEHzF00UazOUp879zUuLwJ6J300BH2DMH29Pww/4mOR3oHXv4F/CL

Sample Code:

-(NSURL *)createReqUrl:(NSString *)hostString secure:(BOOL)usessl urlRoot:(NSString*)urlRoot encryptedParam:(NSString *)encryptedparams{
    NSString *encryptString;
    encryptString = nil;



    encryptString = [encryptedparams stringByReplacingOccurrencesOfString:@"+" withString:@"%%2b"];
    encryptString = [encryptString  stringByReplacingOccurrencesOfString:@"/" withString:@"%%2f"];
    encryptString = [encryptString stringByReplacingOccurrencesOfString:@"=" withString:@"%%3d"];
    encryptString = [encryptString stringByReplacingOccurrencesOfString:@"@" withString:@"%%40"];

    NSString *answer = [[NSString alloc] initWithString:urlRoot];
    answer = [[answer stringByAppendingString:encryptString] stringByReplacingOccurrencesOfString:@"%%" withString:@"%"];

    NSString *scheme = nil;
    if (usessl)
        scheme = @"https://";
    else
        scheme = @"http://";

    return [[NSURL alloc] initWithString:[[scheme stringByAppendingString:hostString] stringByAppendingString:answer]];;
}