| File: | Plugins/Facebook Service/AIFacebookOutgoingMessageManager.m |
| Location: | line 54, column 2 |
| Description: | Memory Leak |
| Code is compiled without garbage collection. |
| 1 | // |
| 2 | // AIFacebookOutgoingMessageManager.m |
| 3 | // Adium |
| 4 | // |
| 5 | // Created by Evan Schoenberg on 5/8/08. |
| 6 | // Copyright 2008 The Adium Team. All rights reserved. |
| 7 | // |
| 8 | |
| 9 | #import "AIFacebookOutgoingMessageManager.h" |
| 10 | #import <Adium/AIContentMessage.h> |
| 11 | #import <Adium/AIContentTyping.h> |
| 12 | #import "AIFacebookAccount.h" |
| 13 | |
| 14 | @implementation AIFacebookOutgoingMessageManager |
| 15 | + (void)sendMessageObject:(AIContentMessage *)inContentMessage |
| 16 | { |
| 17 | //This can not be https:// - the message fails to send |
| 18 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.facebook.com/ajax/chat/send.php"] |
| 19 | cachePolicy:NSURLRequestUseProtocolCachePolicy |
| 20 | timeoutInterval:120]; |
| 21 | NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: |
| 22 | [inContentMessage encodedMessage], @"msg_text", |
| 23 | [[NSNumber numberWithLong:(random() % 99999999)] stringValue], @"msg_id", |
| 24 | [[inContentMessage destination] UID], @"to", |
| 25 | [[NSNumber numberWithInt:[[NSDate date] timeIntervalSince1970]] stringValue], @"client_time", |
| 26 | [(AIFacebookAccount *)[inContentMessage source] postFormID], @"post_form_id", |
| 27 | nil0]; |
| 28 | NSData *postData = [AIFacebookAccount postDataForDictionary:dict]; |
| 29 | [request setHTTPMethod:@"POST"]; |
| 30 | [request setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"]; |
| 31 | [request setHTTPBody:postData]; |
| 32 | |
| 33 | AILogWithSignatureAILogWithPrefix ( __PRETTY_FUNCTION__ , @ "Sending %@" , dict ) ;(@"Sending %@",dict); |
| 34 | [[NSURLConnection alloc] initWithRequest:request delegate:self]; |
| 35 | } |
| 36 | |
| 37 | + (void)sendTypingObject:(AIContentTyping *)inContentTyping |
| 38 | { |
| 39 | //This can not be https:// - the message fails to send |
| 40 | NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.facebook.com/ajax/chat/typ.php"] |
| 41 | cachePolicy:NSURLRequestUseProtocolCachePolicy |
| 42 | timeoutInterval:120]; |
| 43 | NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: |
[1] '?' condition evaluates to true. | |
| 44 | (([inContentTyping typingState] == AITyping) ? @"1" : @"0"), @"typ", |
| 45 | [[inContentTyping destination] UID], @"to", |
| 46 | [(AIFacebookAccount *)[inContentTyping source] postFormID], @"post_form_id", |
| 47 | nil0]; |
| 48 | |
| 49 | NSData *postData = [AIFacebookAccount postDataForDictionary:dict]; |
| 50 | [request setHTTPMethod:@"POST"]; |
| 51 | [request setValue:[NSString stringWithFormat:@"%d", [postData length]] forHTTPHeaderField:@"Content-Length"]; |
| 52 | [request setHTTPBody:postData]; |
| 53 | |
[2] Method returns an object with a +1 retain count (owning reference). | |
[3] Object allocated on line 54 is no longer referenced after this point and has a retain count of +1 (object leaked). | |
| 54 | [[NSURLConnection alloc] initWithRequest:request delegate:self]; |
| 55 | } |
| 56 | |
| 57 | + (void)connection:(NSURLConnection *)inConnection didReceiveResponse:(NSURLResponse *)response |
| 58 | { |
| 59 | //This can be called multiple times, for example in the case of a redirect, so each time we reset the data. |
| 60 | } |
| 61 | |
| 62 | + (void)connection:(NSURLConnection *)inConnection didReceiveData:(NSData *)data |
| 63 | { |
| 64 | NSMutableString *receivedString = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding]; |
| 65 | AILogWithSignatureAILogWithPrefix ( __PRETTY_FUNCTION__ , @ "Received %@" , receivedString ) ;(@"Received %@", receivedString); |
| 66 | [receivedString release]; |
| 67 | } |
| 68 | |
| 69 | + (void)connectionDidFinishLoading:(NSURLConnection *)inConnection |
| 70 | { |
| 71 | [inConnection release]; |
| 72 | } |
| 73 | |
| 74 | + (void)connection:(NSURLConnection *)inConnection didFailWithError:(NSError *)error |
| 75 | { |
| 76 | [inConnection release]; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | @end |