Skip to content

Loading…

Memory leak when using credentials #152

Open
sroebert opened this Issue · 0 comments

1 participant

@sroebert

When using a username and password with 'ASIHTTPRequest.m', it uses the '+ (void)removeAuthenticationCredentialsFromSessionStore:(NSDictionary *)credentials' method to avoid adding duplicates to the 'sessionCredentialsList' array.

This method uses the 'isEqual' method to check for similar entries, which does not work correctly for NSDictionary instances. So what happens is that every time a request is made using credentials, the 'sessionCredentialsList' gets another credentials dictionary added.

To avoid this increase of the array, the 'isEqualToDictionary' should be used instead, so the code becomes:

+ (void)removeAuthenticationCredentialsFromSessionStore:(NSDictionary *)credentials
{
    [sessionCredentialsLock lock];
    NSMutableArray *sessionCredentialsList = [[self class] sessionCredentialsStore];
    NSUInteger i;
    for (i=0; i < [sessionCredentialsList count]; i++) {
        NSDictionary *theCredentials = [sessionCredentialsList objectAtIndex:i];
        if ([[theCredentials objectForKey:@"Credentials"] isEqualToDictionary:credentials]) {
            [sessionCredentialsList removeObjectAtIndex:i];
            [sessionCredentialsLock unlock];
            return;
        }
    }
    [sessionCredentialsLock unlock];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.