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).
This commit is contained in:
Fabian Mastenbroek 2022-06-09 23:02:01 +02:00
parent db733032e0
commit 40cb92a7a5
No known key found for this signature in database
GPG Key ID: 405FC6F81F0A7B85

View File

@ -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];
}
}