Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
🔒 Add multiple safeguards against memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
GitSquared committed Aug 29, 2018
1 parent 2dfa435 commit b37ef49
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ window.themeChanger = (theme) => {
e.setAttribute("class", "mod_column");
});
document.querySelectorAll(".mod_column > div").forEach(e => {e.remove()});
document.querySelectorAll("div.smoothie-chart-tooltip").forEach(e => {e.remove()});

window.term = new Terminal({
role: "client",
Expand Down
2 changes: 1 addition & 1 deletion src/classes/locationGlobe.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class LocationGlobe {
// Connections
this.conns = [];
this.addConn = ip => {
require("https").get({"host": "ipinfo.now.sh", "port": 443, "path": "/"+ip}, (res) => {
require("https").get({host: "ipinfo.now.sh", port: 443, path: "/"+ip, agent: false}, (res) => {
let rawData = "";
res.on("data", (chunk) => {
rawData += chunk;
Expand Down
53 changes: 33 additions & 20 deletions src/classes/netstat.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class Netstat {
</div>`;

this.offline = false;
this.lastconn = {_ended: true};

this._httpsAgent = new require("https").Agent({
keepAlive: false,
maxSockets: 10
});

// Init updaters
this.updateInfo();
Expand Down Expand Up @@ -54,27 +60,34 @@ class Netstat {
if (net.ip4 === "127.0.0.1") {
offline = true;
} else {
require("https").get({"host": "ipinfo.now.sh", "port": 443, "path": "/"}, (res) => {
let rawData = "";
res.on("data", (chunk) => {
rawData += chunk;
});
res.on("end", () => {
try {
this.ipinfo = JSON.parse(rawData);
let ip = this.ipinfo.ip;
document.querySelector("#mod_netstat_innercontainer > div:nth-child(2) > h2").innerHTML = ip;
} catch(e) {
console.warn(e);
console.info(json);
let electron = require("electron");
electron.ipcRenderer.send("log", "note", "NetStat: Error parsing data from ipinfo.now.sh");
electron.ipcRenderer.send("log", "debug", `Error: ${e}`);
}
if (this.lastconn._ended) {
this.lastconn = require("https").get({host: "ipinfo.now.sh", port: 443, path: "/", agent: this._httpsAgent}, (res) => {
let rawData = "";
res.on("data", (chunk) => {
rawData += chunk;
});
res.on("end", () => {
try {
this.ipinfo = JSON.parse(rawData);

if (this.ipinfo.api_version !== "2.0.0") console.warn("Warning: ipinfo API version might not be compatible");

delete this.ipinfo.api_version;
delete this.ipinfo.time;
let ip = this.ipinfo.ip;
document.querySelector("#mod_netstat_innercontainer > div:nth-child(2) > h2").innerHTML = ip;
} catch(e) {
console.warn(e);
console.info(json);
let electron = require("electron");
electron.ipcRenderer.send("log", "note", "NetStat: Error parsing data from ipinfo.now.sh");
electron.ipcRenderer.send("log", "debug", `Error: ${e}`);
}
});
}).on("error", (e) => {
// Drop it
});
}).on("error", (e) => {
// Drop it
});
}

this.si.inetLatency("1.1.1.1", (data) => {
let ping;
Expand Down

0 comments on commit b37ef49

Please sign in to comment.