From eface3f3b32ba270a3388f06710181c886a898b1 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Mon, 30 Mar 2020 11:33:31 +1100 Subject: [PATCH] process needs to be disposed of (#252) --- src/Microsoft.Tye.Core/ProcessUtil.cs | 3 ++- src/Microsoft.Tye.Hosting/ProcessRunner.cs | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.Tye.Core/ProcessUtil.cs b/src/Microsoft.Tye.Core/ProcessUtil.cs index 103ea3a6..60d9a133 100644 --- a/src/Microsoft.Tye.Core/ProcessUtil.cs +++ b/src/Microsoft.Tye.Core/ProcessUtil.cs @@ -144,7 +144,8 @@ namespace Microsoft.Tye { try { - Process.GetProcessById(pid)?.Kill(); + using var process = Process.GetProcessById(pid); + process?.Kill(); } catch (ArgumentException) { } catch (InvalidOperationException) { } diff --git a/src/Microsoft.Tye.Hosting/ProcessRunner.cs b/src/Microsoft.Tye.Hosting/ProcessRunner.cs index 6ad4accb..3238ae51 100644 --- a/src/Microsoft.Tye.Hosting/ProcessRunner.cs +++ b/src/Microsoft.Tye.Hosting/ProcessRunner.cs @@ -332,8 +332,8 @@ namespace Microsoft.Tye.Hosting private static string? GetDotnetRoot() { - var process = Process.GetCurrentProcess(); - var entryPointFilePath = process.MainModule.FileName; + var entryPointFilePath = GetEntryPointFilePath(); + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Path.GetFileNameWithoutExtension(entryPointFilePath) == "dotnet") { @@ -347,6 +347,12 @@ namespace Microsoft.Tye.Hosting return null; } + private static string GetEntryPointFilePath() + { + using var process = Process.GetCurrentProcess(); + return process.MainModule.FileName; + } + private class ProcessInfo {