Memory leak when using credentials #152

sroebert opened this Issue Mar 17, 2011 · 0 comments


None yet
1 participant

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];
    [sessionCredentialsLock unlock];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment