Skip to content

Commit

Permalink
Fixed possible crash issues
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jan 5, 2025
1 parent 0381615 commit 7c1e5a3
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions v2rayN/ServiceLib/Common/ProcUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static async Task ProcessKill(Process? proc, bool review)
return;
}

var procId = review ? proc?.Id : null;
var fileName = review ? proc?.MainModule?.FileName : null;
var processName = review ? proc?.ProcessName : null;

Expand All @@ -90,15 +91,27 @@ public static async Task ProcessKill(Process? proc, bool review)
try { proc?.Dispose(); } catch (Exception ex) { Logging.SaveLog(_tag, ex); }

await Task.Delay(300);
if (review && fileName != null)
if (review && procId != null && fileName != null)
{
var proc2 = Process.GetProcessesByName(processName)
.FirstOrDefault(t => t.MainModule?.FileName == fileName);
if (proc2 != null)
try
{
Logging.SaveLog($"{_tag}, KillProcess not completing the job");
await ProcessKill(proc2, false);
proc2 = null;
var lstProc = Process.GetProcessesByName(processName);
foreach (var proc2 in lstProc)
{
if (proc2.Id == procId)
{
Logging.SaveLog($"{_tag}, KillProcess not completing the job, procId");
await ProcessKill(proc2, false);
}
if (proc2.MainModule != null && proc2.MainModule?.FileName == fileName)
{
Logging.SaveLog($"{_tag}, KillProcess not completing the job, fileName");
}
}
}
catch (Exception ex)
{
Logging.SaveLog(_tag, ex);
}
}
}
Expand Down

0 comments on commit 7c1e5a3

Please sign in to comment.