Objective-C Result from a Static Method saved to class instance variable giving "EXC_BAD_ACCESS" when used.
Posted
by
KinGBin
on Stack Overflow
See other posts from Stack Overflow
or by KinGBin
Published on 2011-01-12T04:42:03Z
Indexed on
2011/01/12
4:53 UTC
Read the original article
Hit count: 173
I am trying to store the md5 string as a class instance variable instead of the actual password. I have a static function that will return a md5 string which I'm trying to store in an instance variable instead of the actual password.
I have the following setter for my class instance variable:
-(void)setPassword:(NSString *)newpass{
if(newpass != password){
password = [utils md5HexDigest:newpass];
}
}
This will pass back the correct md5 string and save it to the password variable in my init function: [self setPassword:pword];.
If I call another instance method and try to access self.password" I will get "EXC_BAD_ACCESS".
I understand that the memory is getting released, but I have no clue to make sure it stays.
I have tried alloc init with autorelease with no luck.
This is the md5HexDigest function getting called during the init (graciously found in another stackoverflow question):
+ (NSString*)md5HexDigest:(NSString*)input {
const char* str = [input UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(str, strlen(str), result);
NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2];
for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {
[ret appendFormat:@"%02x",result[i]];
}
return ret; }
Any help/pointers would be greatly appreciated. I would rather have the md5 string saved in memory than the actual password calling the md5 every time I needed to use the password.
Thanks in advance.
© Stack Overflow or respective owner