Browse Source

fix: memory leak in desktopCapturer.getSources (#27058)

Co-authored-by: Jeremy Rose <[email protected]>
trop[bot] 4 years ago
parent
commit
ba76f6846e
1 changed files with 4 additions and 1 deletions
  1. 4 1
      lib/browser/desktop-capturer.ts

+ 4 - 1
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);
     }
   });