Skip to content

[BUG] Child processes not disposed - massive handle leaks #3366

@clairernovotny

Description

Please confirm these before moving forward

  • I have searched for my issue and have not found a work-in-progress/duplicate/resolved issue.
  • I have tested that this issue has not been fixed in the latest (beta or stable) release.
  • I have checked the FAQ section for solutions.
  • This issue is about a bug (if it is not, please use the correct template).

UniGetUI Version

3.1.6

Windows version, edition, and architecture

Win 11 24H2

Describe your issue

My system was starting to crawl when I noticed that there were hundreds, or more, child conhost/PowerShell (7) child processes still active. Looking at the code here, https://github.com/marticliment/UniGetUI/blob/main/src/UniGetUI.PackageEngine.Managers.PowerShell7/PowerShell7.cs#L59, I noticed that Dispose is never called on the Process, either directly or in a using block. This is likely the culprit.

As you can see in the Remarks section of the docs, they emphasize the need to call Dispose to ensure handles aren't leaked: https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process?view=net-9.0&redirectedfrom=MSDN#remarks.

The docs for Process.WaitForExit also explicitly says to call Close after to free up resources, and Process.Close says that its Dispose method will call Close for you.

This issue may be present in other areas of the code--all Process instances need to be Disposed.

I recommend to enable the CA2000: Dispose objects before losing scope analyzer to help catch these going forward. https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2000

Steps to reproduce the issue

Leave Uniget UI running for a while and notice the buildup of running child processes

UniGetUI Log

n/a

Package Managers Logs

n/a

Relevant information

n/a - this bug is self-evident by reading the code.

Screenshots and videos

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions