Browse Source

mac-virtualcam: Fix port leakage in Mach server

This change fixes an issue in the Mach server exposed by the macOS
virtual camera for OBS, where it would not invalidate ports that were
disconnected by the remote application, causing sporadic crashes.

These crashes can be reproduced in the previous builds by opening the
virtual camera in a remote application and closing the application
(without stopping the virtual camera).
Fabian Mastenbroek 3 years ago
parent
commit
40cb92a7a5
1 changed files with 6 additions and 1 deletions
  1. 6 1
      plugins/mac-virtualcam/src/obs-plugin/OBSDALMachServer.mm

+ 6 - 1
plugins/mac-virtualcam/src/obs-plugin/OBSDALMachServer.mm

@@ -101,19 +101,24 @@
 				     receivePort:nil
 				      components:components];
 			message.msgid = msgId;
-			if (![message
+			if (![port isValid] ||
+			    ![message
 				    sendBeforeDate:
 					    [NSDate dateWithTimeIntervalSinceNow:
 							    1.0]]) {
 				blog(LOG_DEBUG,
 				     "failed to send message to %d, removing it from the clients!",
 				     ((NSMachPort *)port).machPort);
+
+				[port invalidate];
 				[removedPorts addObject:port];
 			}
 		} @catch (NSException *exception) {
 			blog(LOG_DEBUG,
 			     "failed to send message (exception) to %d, removing it from the clients!",
 			     ((NSMachPort *)port).machPort);
+
+			[port invalidate];
 			[removedPorts addObject:port];
 		}
 	}