Fixed the stupid crash on turning off network sharing.
[MenuTunes.git] / NetworkController.m
index 49b8321..70994df 100755 (executable)
@@ -78,10 +78,10 @@ static NetworkController *sharedController;
             serverConnection = [[NSConnection alloc] initWithReceivePort:serverPort
                                                      sendPort:serverPort];
             clientProxy = [[NetworkObject alloc] init];
             serverConnection = [[NSConnection alloc] initWithReceivePort:serverPort
                                                      sendPort:serverPort];
             clientProxy = [[NetworkObject alloc] init];
-            [serverConnection setRootObject:[clientProxy autorelease]];
+            [serverConnection setRootObject:clientProxy];
             [serverConnection registerName:@"ITMTPlayerHost"];
         NS_HANDLER
             [serverConnection registerName:@"ITMTPlayerHost"];
         NS_HANDLER
-            [[serverConnection rootObject] release];
+            [clientProxy release];
             [serverConnection setRootObject:nil];
             [serverConnection release];
             [serverPort release];
             [serverConnection setRootObject:nil];
             [serverConnection release];
             [serverPort release];
@@ -110,9 +110,10 @@ static NetworkController *sharedController;
     } else if (serverOn && !status && [serverConnection isValid]) {
         //Turn off
         [service stop];
     } else if (serverOn && !status && [serverConnection isValid]) {
         //Turn off
         [service stop];
+        [clientProxy invalidate];
         [serverConnection registerName:nil];
         [serverConnection registerName:nil];
+        [serverConnection setRootObject:nil];
         [serverConnection release];
         [serverConnection release];
-        [clientProxy release];
         ITDebugLog(@"Stopped server.");
         serverOn = NO;
     }
         ITDebugLog(@"Stopped server.");
         serverOn = NO;
     }
@@ -200,6 +201,7 @@ static NetworkController *sharedController;
     NSConnection *testConnection;
     NSSocketPort *testPort;
     NetworkObject *tempProxy;
     NSConnection *testConnection;
     NSSocketPort *testPort;
     NetworkObject *tempProxy;
+    BOOL valid;
     ITDebugLog(@"Checking for shared remote at %@.", host);
     if (fullPass) {
         [fullPass getBytes:&buffer range:NSMakeRange(6, 4)];
     ITDebugLog(@"Checking for shared remote at %@.", host);
     if (fullPass) {
         [fullPass getBytes:&buffer range:NSMakeRange(6, 4)];
@@ -216,6 +218,7 @@ static NetworkController *sharedController;
         [testConnection setReplyTimeout:2];
         tempProxy = (NetworkObject *)[testConnection rootProxy];
         [tempProxy serverName];
         [testConnection setReplyTimeout:2];
         tempProxy = (NetworkObject *)[testConnection rootProxy];
         [tempProxy serverName];
+        valid = [tempProxy isValid];
     NS_HANDLER
         ITDebugLog(@"Connection to host failed: %@", host);
         [testConnection release];
     NS_HANDLER
         ITDebugLog(@"Connection to host failed: %@", host);
         [testConnection release];
@@ -231,7 +234,7 @@ static NetworkController *sharedController;
     }
     [testConnection release];
     [testPort release];
     }
     [testConnection release];
     [testPort release];
-    return YES;
+    return valid;
 }
 
 - (BOOL)isServerOn
 }
 
 - (BOOL)isServerOn