From 6a3679dc5572685b8df76c85d912d9cb9ad1a8dc Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Wed, 16 Dec 2020 16:11:39 -0800 Subject: [PATCH] fix: memory leak in desktopCapturer.getSources (#27031) --- lib/browser/desktop-capturer.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/browser/desktop-capturer.ts b/lib/browser/desktop-capturer.ts index b1dfa5077998..885319e4296c 100644 --- a/lib/browser/desktop-capturer.ts +++ b/lib/browser/desktop-capturer.ts @@ -48,6 +48,9 @@ export const getSourcesImpl = (event: Electron.IpcMainEvent | null, args: Electr } // Remove from currentlyRunning once we resolve or reject currentlyRunning = currentlyRunning.filter(running => running.options !== options); + if (event) { + event.sender.removeListener('destroyed', stopRunning); + } }; capturer._onerror = (error: string) => { @@ -66,7 +69,7 @@ export const getSourcesImpl = (event: Electron.IpcMainEvent | null, args: Electr // reference to emit and the capturer itself so that it never dispatches // back to the renderer if (event) { - event.sender.once('destroyed', () => stopRunning()); + event.sender.once('destroyed', stopRunning); } });