adium 2830:c770142607e4: If Bonjour disconnects but the user ope...

commits at adium.im commits at adium.im
Sat Oct 31 17:28:31 UTC 2009


details:	http://hg.adium.im/adium/rev/c770142607e4
revision:	2830:c770142607e4
author:		Evan Schoenberg
date:		Sat Oct 31 12:31:33 2009 -0500

If Bonjour disconnects but the user opens a contact window in the moment before the contact disappears from the list, it wass possible to attempt to open with a nil avInstanceName. Furthermore, if Bonjour disconnects, attempting to send a message to a still-open Bonjour chat could try to reference avInstanceName which would previously be nil after disconnect.

There's no reason to be so aggressive with having avInstanceName only be set while logged in; it's a single string, and it doesn't generally change. We'll create it in init and destroy it in dealloc for AWEzvContactManager.

Fixes #11799 fully.

diffs (74 lines):

diff -r fa28661f40dd -r c770142607e4 Plugins/Bonjour/libezv/Private Classes/AWEzvContactManager.m
--- a/Plugins/Bonjour/libezv/Private Classes/AWEzvContactManager.m	Sat Oct 31 12:18:11 2009 -0500
+++ b/Plugins/Bonjour/libezv/Private Classes/AWEzvContactManager.m	Sat Oct 31 12:31:33 2009 -0500
@@ -42,6 +42,23 @@
 		contacts = [[NSMutableDictionary alloc] init];
 		client = newClient;
 		isConnected = NO;
+		
+		/* find username and computer name */
+		CFStringRef consoleUser = SCDynamicStoreCopyConsoleUser(NULL, NULL, NULL);
+		CFStringRef computerName = SCDynamicStoreCopyLocalHostName(NULL);
+		if (!computerName) {
+			/* computerName can return NULL if the computer name is not set or an error occurs */
+			CFUUIDRef	uuid;
+			
+			uuid = CFUUIDCreate(NULL);
+			computerName = CFUUIDCreateString(NULL, uuid);
+			CFRelease(uuid);		
+		}
+		avInstanceName = [[NSString alloc] initWithFormat:@"%@@%@",
+						  (consoleUser ? (NSString *)consoleUser : @""),
+						  (computerName ? (NSString *)computerName : @"")];
+		if (consoleUser) CFRelease(consoleUser);
+		if (computerName) CFRelease(computerName);		
 	}
 
     return self;
@@ -71,7 +88,9 @@
 - (void)dealloc {
 	/* AWEzvContactManagerListener adds an observer; remove it */
 	[[NSNotificationCenter defaultCenter] removeObserver:self];
-	[userAnnounceData release];
+
+	[userAnnounceData release]; userAnnounceData = nil;
+	[avInstanceName release]; avInstanceName = nil;
 
 	[super dealloc];
 }
diff -r fa28661f40dd -r c770142607e4 Plugins/Bonjour/libezv/Private Classes/AWEzvContactManagerRendezvous.m
--- a/Plugins/Bonjour/libezv/Private Classes/AWEzvContactManagerRendezvous.m	Sat Oct 31 12:18:11 2009 -0500
+++ b/Plugins/Bonjour/libezv/Private Classes/AWEzvContactManagerRendezvous.m	Sat Oct 31 12:31:33 2009 -0500
@@ -159,22 +159,7 @@
 	[userAnnounceData setField:@"version" content:@"1"];
 
 	[self setStatus:[client status] withMessage:nil];
-
-	/* find username and computer name */
-	CFStringRef consoleUser = SCDynamicStoreCopyConsoleUser(NULL, NULL, NULL);
-	CFStringRef computerName = SCDynamicStoreCopyLocalHostName(NULL);
-	if (!computerName) {
-		/* computerName can return NULL if the computer name is not set or an error occurs */
-		CFUUIDRef	uuid;
-
-		uuid = CFUUIDCreate(NULL);
-		computerName = CFUUIDCreateString(NULL, uuid);
-		CFRelease(uuid);		
-	}
-    avInstanceName = [NSString stringWithFormat:@"%@@%@", (consoleUser ? (NSString *)consoleUser : @""), (computerName ? (NSString *)computerName : @"")];
-	if (consoleUser) CFRelease(consoleUser);
-	if (computerName) CFRelease(computerName);
-	[avInstanceName retain];
+	
     /* register service with mDNSResponder */
 
 	DNSServiceRef servRef;
@@ -226,8 +211,6 @@
 
 		avDNSReference = nil;
 		imageServiceRef = nil;
-		
-		[avInstanceName release]; avInstanceName = nil;
 	}
 
 	[self setConnected:NO];




More information about the commits mailing list