Skip to content

Commit 20cd3ac

Browse files
committed
Properly dispose Process instances (fix #3366)
1 parent d73e3ce commit 20cd3ac

23 files changed

Lines changed: 49 additions & 49 deletions

File tree

src/UniGetUI.Core.Data/CoreData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ private static int GetCodePage()
377377
{
378378
try
379379
{
380-
Process p = new Process
380+
using Process p = new Process
381381
{
382382
StartInfo = new ProcessStartInfo
383383
{

src/UniGetUI.Core.Tools/Tools.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ Inner exception ({i}):
264264
/// <param name="RunAsAdmin">Whether the batch file should be launched elevated or not</param>
265265
public static async void LaunchBatchFile(string path, string WindowTitle = "", bool RunAsAdmin = false)
266266
{
267-
Process p = new();
267+
using Process p = new();
268268
p.StartInfo.FileName = "cmd.exe";
269269
p.StartInfo.Arguments = "/C start \"" + WindowTitle + "\" \"" + path + "\"";
270270
p.StartInfo.UseShellExecute = true;
@@ -501,7 +501,7 @@ public static string EnsureSafeQueryString(string query)
501501
public static async Task CacheUACForCurrentProcess()
502502
{
503503
Logger.Info("Caching admin rights for process id " + Environment.ProcessId);
504-
Process p = new()
504+
using Process p = new()
505505
{
506506
StartInfo = new ProcessStartInfo
507507
{
@@ -525,7 +525,7 @@ public static async Task CacheUACForCurrentProcess()
525525
public static async Task ResetUACForCurrentProcess()
526526
{
527527
Logger.Info("Resetting administrator rights cache for process id " + Environment.ProcessId);
528-
Process p = new()
528+
using Process p = new()
529529
{
530530
StartInfo = new ProcessStartInfo
531531
{

src/UniGetUI.PackageEngine.Managers.Cargo/Cargo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public Cargo()
7373

7474
protected override IReadOnlyList<Package> FindPackages_UnSafe(string query)
7575
{
76-
Process p = GetProcess(Status.ExecutablePath, "search -q --color=never " + query);
76+
using Process p = GetProcess(Status.ExecutablePath, "search -q --color=never " + query);
7777
IProcessTaskLogger logger = TaskLogger.CreateNew(LoggableTaskType.FindPackages, p);
7878
p.Start();
7979

@@ -142,7 +142,7 @@ protected override ManagerStatus LoadManager()
142142
return new(){ ExecutablePath = executablePath, Found = false, Version = ""};
143143
}
144144

145-
Process p = GetProcess(executablePath, "--version");
145+
using Process p = GetProcess(executablePath, "--version");
146146
p.Start();
147147
string version = p.StandardOutput.ReadToEnd().Trim();
148148
string error = p.StandardError.ReadToEnd();
@@ -174,7 +174,7 @@ private IReadOnlyList<Package> GetPackages(LoggableTaskType taskType)
174174
private List<Match> GetInstalledCommandOutput()
175175
{
176176
List<Match> output = [];
177-
Process p = GetProcess(Status.ExecutablePath, "install-update --list");
177+
using Process p = GetProcess(Status.ExecutablePath, "install-update --list");
178178
IProcessTaskLogger logger = TaskLogger.CreateNew(LoggableTaskType.OtherTask, p);
179179
logger.AddToStdOut("Other task: Call the install-update command");
180180
p.Start();

src/UniGetUI.PackageEngine.Managers.Chocolatey/Chocolatey.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public Chocolatey()
6565

6666
protected override IReadOnlyList<Package> GetAvailableUpdates_UnSafe()
6767
{
68-
Process p = new()
68+
using Process p = new()
6969
{
7070
StartInfo = new ProcessStartInfo
7171
{
@@ -119,7 +119,7 @@ protected override IReadOnlyList<Package> GetAvailableUpdates_UnSafe()
119119

120120
protected override IReadOnlyList<Package> _getInstalledPackages_UnSafe()
121121
{
122-
Process p = new()
122+
using Process p = new()
123123
{
124124
StartInfo = new ProcessStartInfo
125125
{

src/UniGetUI.PackageEngine.Managers.Chocolatey/Helpers/ChocolateyDetailsHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public ChocolateyDetailsHelper(BaseNuGet manager) : base(manager)
1313

1414
protected override IReadOnlyList<string> GetInstallableVersions_UnSafe(IPackage package)
1515
{
16-
Process p = new()
16+
using Process p = new()
1717
{
1818
StartInfo = new ProcessStartInfo
1919
{

src/UniGetUI.PackageEngine.Managers.Chocolatey/Helpers/ChocolateySourceHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected override IReadOnlyList<IManagerSource> GetSources_UnSafe()
3535
{
3636
List<ManagerSource> sources = [];
3737

38-
Process p = new()
38+
using Process p = new()
3939
{
4040
StartInfo = new()
4141
{

src/UniGetUI.PackageEngine.Managers.Dotnet/DotNet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected override IReadOnlyList<Package> _getInstalledPackages_UnSafe()
6262
List<Package> Packages = [];
6363
foreach (var options in new OverridenInstallationOptions[] { new(PackageScope.Local), new(PackageScope.Global) })
6464
{
65-
Process p = new()
65+
using Process p = new()
6666
{
6767
StartInfo = new ProcessStartInfo
6868
{

src/UniGetUI.PackageEngine.Managers.Npm/Helpers/NpmPkgDetailsHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected override IReadOnlyList<Uri> GetScreenshots_UnSafe(IPackage package)
9393

9494
protected override IReadOnlyList<string> GetInstallableVersions_UnSafe(IPackage package)
9595
{
96-
Process p = new()
96+
using Process p = new()
9797
{
9898
StartInfo = new ProcessStartInfo
9999
{

src/UniGetUI.PackageEngine.Managers.Npm/Npm.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Npm()
4747

4848
protected override IReadOnlyList<Package> FindPackages_UnSafe(string query)
4949
{
50-
Process p = new()
50+
using Process p = new()
5151
{
5252
StartInfo = new ProcessStartInfo
5353
{
@@ -99,7 +99,7 @@ protected override IReadOnlyList<Package> GetAvailableUpdates_UnSafe()
9999
List<Package> Packages = [];
100100
foreach (var options in new OverridenInstallationOptions[] { new(PackageScope.Local), new(PackageScope.Global) })
101101
{
102-
Process p = new()
102+
using Process p = new()
103103
{
104104
StartInfo = new ProcessStartInfo
105105
{
@@ -145,7 +145,7 @@ protected override IReadOnlyList<Package> GetInstalledPackages_UnSafe()
145145
List<Package> Packages = [];
146146
foreach (var options in new OverridenInstallationOptions[] { new(PackageScope.Local), new(PackageScope.Global) })
147147
{
148-
Process p = new()
148+
using Process p = new()
149149
{
150150
StartInfo = new ProcessStartInfo
151151
{

src/UniGetUI.PackageEngine.Managers.Pip/Helpers/PipPkgDetailsHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected override IReadOnlyList<Uri> GetScreenshots_UnSafe(IPackage package)
9696

9797
protected override IReadOnlyList<string> GetInstallableVersions_UnSafe(IPackage package)
9898
{
99-
Process p = new()
99+
using Process p = new()
100100
{
101101
StartInfo = new ProcessStartInfo
102102
{

0 commit comments

Comments
 (0)