Skip to content
This repository was archived by the owner on Nov 20, 2023. It is now read-only.

Commit eface3f

Browse files
authored
process needs to be disposed of (#252)
1 parent 9a2b179 commit eface3f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Microsoft.Tye.Core/ProcessUtil.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ public static void KillProcess(int pid)
144144
{
145145
try
146146
{
147-
Process.GetProcessById(pid)?.Kill();
147+
using var process = Process.GetProcessById(pid);
148+
process?.Kill();
148149
}
149150
catch (ArgumentException) { }
150151
catch (InvalidOperationException) { }

src/Microsoft.Tye.Hosting/ProcessRunner.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ private void WriteReplicaToStore(string pid)
332332

333333
private static string? GetDotnetRoot()
334334
{
335-
var process = Process.GetCurrentProcess();
336-
var entryPointFilePath = process.MainModule.FileName;
335+
var entryPointFilePath = GetEntryPointFilePath();
336+
337337
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
338338
Path.GetFileNameWithoutExtension(entryPointFilePath) == "dotnet")
339339
{
@@ -347,6 +347,12 @@ private void WriteReplicaToStore(string pid)
347347
return null;
348348
}
349349

350+
private static string GetEntryPointFilePath()
351+
{
352+
using var process = Process.GetCurrentProcess();
353+
return process.MainModule.FileName;
354+
}
355+
350356
private class ProcessInfo
351357
{
352358

0 commit comments

Comments
 (0)