Repository navigation
fix: dispose ManagementObject in MemoryTestService and SkiaSharp paints in NetworkSharedState - #441
Conversation
…ts in NetworkSharedState
📝 WalkthroughWalkthroughThis PR fixes two unmanaged resource leaks: WMI ChangesResource Leak Fixes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
SysManager/SysManager/Services/MemoryTestService.cs (1)
102-105:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDispose the
ManagementObjectCollectionreturned bys.Get()Line 104 enumerates
s.Get()directly without disposing the returned collection, which is a resource leak. Other files in the codebase (SystemInfoService.cs, DiskHealthService.cs, BatteryService.cs, FixedDriveService.cs) correctly wrap this call withusing var, but MemoryTestService.cs fails to do so.Wrap the result in a
usingstatement before the foreach loop:Proposed fix
using var s = new ManagementObjectSearcher( "SELECT BankLabel, DeviceLocator, Manufacturer, Capacity, Speed, ConfiguredClockSpeed, PartNumber FROM Win32_PhysicalMemory"); - foreach (ManagementObject mo in s.Get()) + using var modules = s.Get(); + foreach (ManagementObject mo in modules) { using (mo) {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@SysManager/SysManager/Services/MemoryTestService.cs` around lines 102 - 105, The ManagementObjectCollection returned by ManagementObjectSearcher.Get() in MemoryTestService (the call s.Get() used in the foreach) must be disposed to avoid a resource leak; change the foreach to first capture the collection in a using (e.g. using var collection = s.Get()) and then iterate over that collection (foreach (ManagementObject mo in collection)), mirroring the pattern used in SystemInfoService.cs and others so the ManagementObjectCollection is properly disposed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@SysManager/SysManager/Services/MemoryTestService.cs`:
- Around line 102-105: The ManagementObjectCollection returned by
ManagementObjectSearcher.Get() in MemoryTestService (the call s.Get() used in
the foreach) must be disposed to avoid a resource leak; change the foreach to
first capture the collection in a using (e.g. using var collection = s.Get())
and then iterate over that collection (foreach (ManagementObject mo in
collection)), mirroring the pattern used in SystemInfoService.cs and others so
the ManagementObjectCollection is properly disposed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f7d57dc9-4112-4e77-930c-9a454f4ec398
📒 Files selected for processing (3)
CHANGELOG.mdSysManager/SysManager/Services/MemoryTestService.csSysManager/SysManager/ViewModels/NetworkSharedState.cs
📜 Review details
🔇 Additional comments (2)
SysManager/SysManager/ViewModels/NetworkSharedState.cs (1)
263-269: LGTM!Also applies to: 561-587
CHANGELOG.md (1)
9-16: LGTM!
Adds CHANGELOG entry for v0.28.26 — CodeQL regression fixes (missed-where + missed-using). Co-authored-by: laurentiu021 <laurentiu021@users.noreply.github.com>
Adds CHANGELOG entry for v0.28.26 — CodeQL regression fixes (missed-where + missed-using). Co-authored-by: laurentiu021 <laurentiu021@users.noreply.github.com>
…ts in NetworkSharedState (#441) Co-authored-by: laurentiu021 <laurentiu021@users.noreply.github.com>
Summary
Fix two resource leaks identified in the full code review (LEAK-003, LEAK-007 subset).
Changes
MemoryTestService.cs
ManagementObject moinusing (mo)inside theGetModulesAsyncforeach loop.Without this, each WMI object's native COM handle leaks until GC finalizer runs.
NetworkSharedState.cs
Dispose()now disposes all SkiaSharp paint resources:DisposeSeriesnow handles bothLineSeries<DateTimePoint>andLineSeries<ObservablePoint>DisposeAxisPaintshelper methodPreviously fixed (verified, no action needed)
using (mo)using)using var streamusing var procTesting