From 40cb92a7a52bf7f2b17a4e47570ece2c0e22be5e Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Thu, 9 Jun 2022 23:02:01 +0200 Subject: [PATCH] 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). --- plugins/mac-virtualcam/src/obs-plugin/OBSDALMachServer.mm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/mac-virtualcam/src/obs-plugin/OBSDALMachServer.mm b/plugins/mac-virtualcam/src/obs-plugin/OBSDALMachServer.mm index a1b141a45..d2857766e 100644 --- a/plugins/mac-virtualcam/src/obs-plugin/OBSDALMachServer.mm +++ b/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]; } }