Skip to content

fix: code quality — paint leak, stable chart offset, PerformanceVM dispose#409

Merged
laurentiu021 merged 1 commit into
mainfrom
fix/code-quality-batch
May 15, 2026
Merged

fix: code quality — paint leak, stable chart offset, PerformanceVM dispose#409
laurentiu021 merged 1 commit into
mainfrom
fix/code-quality-batch

Conversation

@laurentiu021

@laurentiu021 laurentiu021 commented May 15, 2026

Copy link
Copy Markdown
Owner

Summary

Addresses MEDIUM code quality findings from the comprehensive code review.

Fixes

  • CQ-M1 — NetworkSharedState: SkiaSharp SolidColorPaint objects (Stroke, GeometryStroke, GeometryFill) are now disposed when a ping target is removed. Previously, each removal leaked unmanaged SKPaint handles.
  • CQ-M2 — NetworkSharedState: Latency chart visual offset now uses a stable hash of the target host instead of Targets.IndexOf(). Previously, removing a target shifted all remaining indices, causing visual jumps on the chart.
  • CQ-M4 — PerformanceViewModel: Added Dispose(bool) override to satisfy the ViewModelBase disposal contract and clean up the snapshot reference.

Files changed (3)

ViewModels: NetworkSharedState, PerformanceViewModel
Docs: CHANGELOG.md

Build

0 errors, 0 new warnings.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed unmanaged resource leaks in network monitoring charts that could impact system performance
    • Stabilized latency chart display when ping targets are removed or reordered
    • Improved cleanup when navigating away from the performance monitoring view

Review Change Stack

…spose

- CQ-M1: Dispose SkiaSharp paint objects when removing ping targets
- CQ-M2: Use stable host-hash offset instead of IndexOf for chart lines
- CQ-M4: PerformanceViewModel overrides Dispose
@coderabbitai

coderabbitai Bot commented May 15, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR fixes resource leaks and chart visualization instability across two view models. NetworkSharedState now disposes SkiaSharp paint resources when targets are removed and replaces index-dependent chart offset with stable host-hash-based offset. PerformanceViewModel adds lifecycle cleanup via a Dispose override. Changes are documented in the 0.48.27 release notes.

Changes

Resource Disposal and Chart Offset Stabilization

Layer / File(s) Summary
Paint Resource Disposal and Chart Offset Stabilization
SysManager/SysManager/ViewModels/NetworkSharedState.cs
RemoveTargetInternal now disposes ISeries paint components (stroke, geometry, fill) via a new DisposeSeries helper before removing series, preventing SKPaint leaks. Latency chart offset is changed from Targets.IndexOf(target) to a stable value derived from target.Host.GetHashCode() % 8 in both FlushPending sample processing and RecomputeStats statistics recalculation, eliminating offset jumps after target removal or reordering.
PerformanceViewModel Lifecycle Cleanup
SysManager/SysManager/ViewModels/PerformanceViewModel.cs
Dispose(bool disposing) override nulls _snapshot and calls base.Dispose(disposing) to ensure cleanup of restore state during navigation and disposal.
Release Notes Documentation
CHANGELOG.md
0.48.27 release entry documents three fixes: paint disposal in NetworkSharedState, latency chart offset stabilization, and PerformanceViewModel disposal cleanup, with corresponding CQ ticket references.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly Related PRs

  • laurentiu021/SystemManager#347: Both PRs fix SkiaSharp unmanaged resource leaks in NetworkSharedState by disposing paint/typeface resources during target removal and disposal lifecycle.
  • laurentiu021/SystemManager#364: Both PRs modify NetworkSharedState chart and resource lifecycle—this PR disposes series paints and adjusts offset logic, while the retrieved PR addresses similar disposal and buffer handling changes.
  • laurentiu021/SystemManager#406: Both PRs modify NetworkSharedState's statistics path—this PR changes latency offset during flush and recompute, while the retrieved PR refactors RecomputeStats computations in the same code area.

Poem

🐰 When targets disappear, no more SKPaint leaks,
Hash offsets keep charts stable through the weeks.
Snapshots disposed, when view models say goodbye,
Resource cleanup done, with 0.48.27 to fly! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the three main fixes in the changeset: paint leak disposal, stable chart offset, and PerformanceVM dispose override.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/code-quality-batch

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 60.00000% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...anager/SysManager/ViewModels/NetworkSharedState.cs 75.00% 0 Missing and 4 partials ⚠️
...ager/SysManager/ViewModels/PerformanceViewModel.cs 0.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@SysManager/SysManager/ViewModels/NetworkSharedState.cs`:
- Around line 253-263: DisposeSeries currently only handles
LineSeries<DateTimePoint>, so LineSeries<ObservablePoint> (used by traceroute)
is skipped and its Stroke/GeometryStroke/GeometryFill/Fill remain undisposed;
update DisposeSeries to detect any LineSeries<T> (not just DateTimePoint) —
e.g., check series.GetType().IsGenericType &&
series.GetType().GetGenericTypeDefinition() == typeof(LineSeries<>) or test for
a non-generic LineSeries base/interface — then cast the instance to a variable
(or use dynamic) and call Dispose on Stroke, GeometryStroke, GeometryFill and
Fill exactly as done for line to ensure all paint resources are disposed for
trace series as well.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6f587684-0d01-4e8e-8feb-291d1077339d

📥 Commits

Reviewing files that changed from the base of the PR and between 42c6af6 and 4aa11dd.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • SysManager/SysManager/ViewModels/NetworkSharedState.cs
  • SysManager/SysManager/ViewModels/PerformanceViewModel.cs
📜 Review details
🔇 Additional comments (3)
CHANGELOG.md (1)

9-19: LGTM!

SysManager/SysManager/ViewModels/NetworkSharedState.cs (1)

341-344: LGTM!

Also applies to: 384-389

SysManager/SysManager/ViewModels/PerformanceViewModel.cs (1)

545-555: LGTM!

Comment on lines +253 to +263
/// <summary>Disposes paint resources attached to a chart series.</summary>
private static void DisposeSeries(ISeries series)
{
if (series is LineSeries<DateTimePoint> line)
{
(line.Stroke as IDisposable)?.Dispose();
(line.GeometryStroke as IDisposable)?.Dispose();
(line.GeometryFill as IDisposable)?.Dispose();
(line.Fill as IDisposable)?.Dispose();
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail
FILE="SysManager/SysManager/ViewModels/NetworkSharedState.cs"

echo "== Series construction and dispose helper =="
rg -n 'LatencySeries.Add|TraceSeries.Add|LineSeries<|DisposeSeries\(' "$FILE"

Repository: laurentiu021/SystemManager

Length of output: 452


🏁 Script executed:

#!/bin/bash
set -euo pipefail
FILE="SysManager/SysManager/ViewModels/NetworkSharedState.cs"

echo "== Context around series creation (lines 150-180) =="
sed -n '150,180p' "$FILE" | cat -n

echo -e "\n== Context around disposal calls (lines 230-250) =="
sed -n '230,250p' "$FILE" | cat -n

echo -e "\n== Full DisposeSeries method (lines 253-270) =="
sed -n '253,270p' "$FILE" | cat -n

Repository: laurentiu021/SystemManager

Length of output: 3338


Dispose helper skips TraceSeries paint resources.

At line 256, DisposeSeries only matches LineSeries<DateTimePoint>, but traceroute uses LineSeries<ObservablePoint> (line 168). When called at line 241, the disposal is skipped for trace series, leaving their paint resources (Stroke, GeometryStroke, GeometryFill) undisposed.

Suggested fix
 private static void DisposeSeries(ISeries series)
 {
-    if (series is LineSeries<DateTimePoint> line)
+    if (series is LineSeries<DateTimePoint> or LineSeries<ObservablePoint>)
     {
-        (line.Stroke as IDisposable)?.Dispose();
-        (line.GeometryStroke as IDisposable)?.Dispose();
-        (line.GeometryFill as IDisposable)?.Dispose();
-        (line.Fill as IDisposable)?.Dispose();
+        ((line.Stroke as IDisposable)?.Dispose();
+        (line.GeometryStroke as IDisposable)?.Dispose();
+        (line.GeometryFill as IDisposable)?.Dispose();
+        (line.Fill as IDisposable)?.Dispose();
     }
 }
🤖 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/ViewModels/NetworkSharedState.cs` around lines 253 -
263, DisposeSeries currently only handles LineSeries<DateTimePoint>, so
LineSeries<ObservablePoint> (used by traceroute) is skipped and its
Stroke/GeometryStroke/GeometryFill/Fill remain undisposed; update DisposeSeries
to detect any LineSeries<T> (not just DateTimePoint) — e.g., check
series.GetType().IsGenericType && series.GetType().GetGenericTypeDefinition() ==
typeof(LineSeries<>) or test for a non-generic LineSeries base/interface — then
cast the instance to a variable (or use dynamic) and call Dispose on Stroke,
GeometryStroke, GeometryFill and Fill exactly as done for line to ensure all
paint resources are disposed for trace series as well.

@laurentiu021
laurentiu021 merged commit 2e20e90 into main May 15, 2026
5 checks passed
@laurentiu021
laurentiu021 deleted the fix/code-quality-batch branch May 15, 2026 14:56
laurentiu021 added a commit that referenced this pull request May 22, 2026
## Summary

**Batch 8** of the QA bug fix series.

### Issue #408 — Update download no SHA256 verification
Added \VerifyHashAsync\ method to \UpdateService\:
- Downloads the \.sha256\ file from the same GitHub release
- Computes SHA256 of the local downloaded file
- Compares and returns \(Verified, ExpectedHash, ActualHash)\
- Best-effort: if \.sha256\ file is unavailable (network error), returns
verified=true to not block install
- Logs hash match/mismatch via Serilog

### Issue #409 — Ookla CLI no hash verification
Added integrity verification to \SpeedTestService.EnsureOoklaAsync\:
- Computes SHA256 of downloaded zip and logs it for audit trail
- Validates the zip is not corrupt (\ZipFile.OpenRead\)
- Verifies the zip contains \speedtest.exe\
- Rejects corrupt/tampered downloads with descriptive error

### Testing
- Build: 0 errors

Closes #408, Closes #409

Co-authored-by: laurentiu021 <laurentiu021@users.noreply.github.com>
laurentiu021 added a commit that referenced this pull request May 22, 2026
Adds CHANGELOG entries for all 9 releases from the QA bug fix session:

- **v0.28.16** — Dispose lifecycle (#395, #410)
- **v0.28.17** — CTS disposal + bare catch (#396, #413)
- **v0.28.18** — Input validation + null checks (#397, #398)
- **v0.28.19** — JSON error handling (#400)
- **v0.28.20** — Drive scanning + cache eviction + ConfigureAwait (#401,
#402, #403)
- **v0.28.21** — Audit logging + error messages (#405, #407)
- **v0.28.22** — SHA256 verification (#408, #409)
- **v0.28.23** — Service timeout + snapshot persist + traceroute DNS
(#414, #415, #416)
- **v0.28.24** — Accessibility (#411)

18 bugs fixed in total.

Co-authored-by: laurentiu021 <laurentiu021@users.noreply.github.com>
laurentiu021 added a commit that referenced this pull request May 22, 2026
…spose (#409)

- CQ-M1: Dispose SkiaSharp paint objects when removing ping targets
- CQ-M2: Use stable host-hash offset instead of IndexOf for chart lines
- CQ-M4: PerformanceViewModel overrides Dispose

Co-authored-by: laurentiu021 <laurentiu021@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants