Browse Source

fix: memory leak in desktopCapturer.getSources (#27031) (#27506)

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

+ 2 - 1
lib/browser/desktop-capturer.ts

@@ -28,6 +28,7 @@ export const getSources = (event: Electron.IpcMainEvent, options: ElectronIntern
       }
       // Remove from currentlyRunning once we resolve or reject
       currentlyRunning = currentlyRunning.filter(running => running.options !== options);
+      event.sender.removeListener('destroyed', stopRunning);
     };
 
     const emitter = new EventEmitter();
@@ -54,7 +55,7 @@ export const getSources = (event: Electron.IpcMainEvent, options: ElectronIntern
     // If the WebContents is destroyed before receiving result, just remove the
     // reference to emit and the capturer itself so that it never dispatches
     // back to the renderer
-    event.sender.once('destroyed', () => stopRunning());
+    event.sender.once('destroyed', stopRunning);
   });
 
   currentlyRunning.push({