Fixed memory leak issues

This commit is contained in:
jsrobson10 2019-04-29 09:04:32 +10:00
parent 1d159570fc
commit bc797a9e12
2 changed files with 43 additions and 23 deletions

View File

@ -350,13 +350,15 @@ function connect(profile, connection_id)
g.users = {};
// RSA child task
g.rsa_task = child_process.fork(
path.resolve('rsa.js'), [],
{
stdio: [ 'pipe', 'pipe', 'pipe', 'ipc' ],
silent: false
}
);
if(!g.rsa_task) {
g.rsa_task = child_process.fork(
path.resolve('rsa.js'), [],
{
stdio: [ 'pipe', 'pipe', 'pipe', 'ipc' ],
silent: false
}
);
}
g.rsa_task.stdout.on('data', function(data)
{
@ -389,24 +391,20 @@ function connect(profile, connection_id)
g.raw_encryption_data_upto = 0;
g.raw_encryption_data_size = 0;
// Create a client
var client;
// Is this direct mode
if(profile.mode == "direct")
{
// Set the client to a direct connection
client = new net.Socket();
g.client = client;
g.client = new net.Socket();
}
// Is this socks5 mode
if(profile.mode == "socks5")
{
// Set the client as a socks proxy
client = socks_new(profile.proxy.hostname, profile.proxy.port);
console.log("Connecting with socks5", profile.proxy.hostname, profile.proxy.port)
g.client = client;
if(!g.client) {
g.client = socks_new(profile.proxy.hostname, profile.proxy.port);
}
}
function rsa_task_send(data)
@ -416,7 +414,7 @@ function connect(profile, connection_id)
}
// Connect to the server
client.connect(port, hostname, function()
g.client.connect(port, hostname, function()
{
console.log("Connected", profile.mode);
// Load the RSA key
@ -426,7 +424,7 @@ function connect(profile, connection_id)
});
// Catch errors
client.on("error", function(e)
g.client.on("error", function(e)
{
// Tell the user
console.log("Connection failed with error ", e);
@ -440,7 +438,7 @@ function connect(profile, connection_id)
}
// Wait for data
client.on('data', function(data)
g.client.on('data', function(data)
{
// Recieve data in order
recieve_ordered(data, recieve_ordered_memory, function(data)
@ -486,7 +484,7 @@ function connect(profile, connection_id)
if(data.error == "auth")
{
// Destroy the connection
client.destroy();
g.client.destroy();
// Delete the connections
delete connections[connection_id];
@ -576,13 +574,16 @@ function connect(profile, connection_id)
});
});
client.on('close', function(data)
g.client.on('close', function(data)
{
console.log("Connection closed:", connection_id)
// Close the connection
delete connections[connection_id];
// Terminate the child processes
g.rsa_task.kill();
// Attempt to restart the connection in 10 seconds
console.log("Attempting reconnection...")
setTimeout(function()
@ -599,7 +600,7 @@ function connect(profile, connection_id)
console.log("Caught error", e);
}
},
1000);
10000);
});
g.rsa_task.on('message', function(message)
@ -622,7 +623,7 @@ function connect(profile, connection_id)
if(data['mode'] == 'get')
{
// Send the public key to the server
client.write(send_ordered(JSON.stringify({
g.client.write(send_ordered(JSON.stringify({
key: data['public'],
mode: "pubkey"
})));
@ -638,7 +639,7 @@ function connect(profile, connection_id)
// Send login
console.log("Sending login")
socket_write(client, g.encryption, {
socket_write(g.client, g.encryption, {
mode: "login",
username: profile.username,
password: profile.password

View File

@ -91,8 +91,27 @@ function profile_connect(id)
// Is the profile set
if(profiles[id])
{
// Allocate some varibles for reusing from an old connection
/*var client;
var rsa_task;
// Is there a connection here
if(connections[id])
{
// Reuse some varibles
var client = connections[id].client;
var rsa_task = connections[id].rsa_task;
console.log("rescued");
}
console.log("clirsa", client, rsa_task)*/
// Reconnect to the server
connections[id] = connect(profiles[id], id);
// Set the old varibles
/*connections[id].client = client;
connections[id].rsa_task = rsa_task;*/
}
else