Skip to content

Commit 060afc3

Browse files
committed
fixed memory leak in main.js from event.reply for give cookies
1 parent c27f60a commit 060afc3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

app/electron/main.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const path = require('path');
2525
// const fs = require('fs');
2626

2727
console.log('NODE ENV is ', process.env.NODE_ENV);
28-
const isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test' ;
28+
const isDev =
29+
process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
2930
const port = 8080;
3031
const selfHost = `http://localhost:${port}`;
3132

@@ -339,8 +340,12 @@ ipcMain.on('set_cookie', event => {
339340
session.defaultSession.cookies
340341
.get({ url: serverUrl })
341342
.then(cookie => {
342-
console.log(cookie);
343-
event.reply('give_cookie', cookie);
343+
// this if statement is necessary or the setInterval on main app will constantly run and will emit this event.reply, causing a memory leak
344+
// checking for a cookie inside array will only emit reply when a cookie exists
345+
if (cookie[0]) {
346+
console.log(cookie);
347+
event.reply('give_cookie', cookie);
348+
}
344349
})
345350
.catch(error => {
346351
console.log('Error giving cookies in set_cookie:', error);

0 commit comments

Comments
 (0)