Skip to content

Commit 175665c

Browse files
BornToBeRootclaude
andauthored
Fix CancellationTokenSource leak in ViewModels (#3448)
* Fix CancellationTokenSource leak in ViewModels Dispose the previous CancellationTokenSource before overwriting it in IPScanner, PortScanner, Traceroute, PingMonitor, PingMonitorHost and SNMP. Each Start() created a new instance without disposing the old one, leaking the WaitHandle allocated by CancellationTokenSource on every run. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Update next-release.md --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ade023a commit 175665c

7 files changed

Lines changed: 7 additions & 0 deletions

File tree

Source/NETworkManager/ViewModels/IPScannerViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ private async Task Start()
440440

441441
DragablzTabItem.SetTabHeader(_tabId, Host);
442442

443+
_cancellationTokenSource?.Dispose();
443444
_cancellationTokenSource = new CancellationTokenSource();
444445

445446
// Resolve hostnames

Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ public async Task Start()
627627
IsStatusMessageDisplayed = false;
628628
IsRunning = true;
629629

630+
_cancellationTokenSource?.Dispose();
630631
_cancellationTokenSource = new CancellationTokenSource();
631632

632633
// Resolve hostnames

Source/NETworkManager/ViewModels/PingMonitorViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ public void Start()
400400
// Reset chart
401401
ResetTimeChart();
402402

403+
_cancellationTokenSource?.Dispose();
403404
_cancellationTokenSource = new CancellationTokenSource();
404405

405406
var ping = new Ping

Source/NETworkManager/ViewModels/PortScannerViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ private async Task Start()
390390

391391
DragablzTabItem.SetTabHeader(_tabId, Host);
392392

393+
_cancellationTokenSource?.Dispose();
393394
_cancellationTokenSource = new CancellationTokenSource();
394395

395396
// Resolve hostnames

Source/NETworkManager/ViewModels/SNMPViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ await DNSClientHelper.ResolveAorAaaaAsync(Host,
502502
ipAddress = dnsResult.Value;
503503
}
504504

505+
_cancellationTokenSource?.Dispose();
505506
_cancellationTokenSource = new CancellationTokenSource();
506507

507508
// SNMP...

Source/NETworkManager/ViewModels/TracerouteViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ private async Task StartTrace()
323323

324324
DragablzTabItem.SetTabHeader(_tabId, Host);
325325

326+
_cancellationTokenSource?.Dispose();
326327
_cancellationTokenSource = new CancellationTokenSource();
327328

328329
// Try to parse the string into an IP-Address

Website/docs/changelog/next-release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ Release date: **xx.xx.2025**
110110

111111
## Dependencies, Refactoring & Documentation
112112

113+
- Fixed `CancellationTokenSource` leak in `IPScanner`, `PortScanner`, `Traceroute`, `PingMonitor`, `PingMonitorHost` and `SNMP` ViewModels. The previous instance was never disposed before being overwritten on each run, leaking the underlying `WaitHandle`. [#3448](https://github.com/BornToBeRoot/NETworkManager/pull/3448)
113114
- Replace fire-and-forget `.ConfigureAwait(false)` calls with explicit discard assignments (`_ = SomeAsyncOperation()`) across command handlers, startup/load paths and profile callbacks. [#3441](https://github.com/BornToBeRoot/NETworkManager/pull/3441)
114115
- Code cleanup & refactoring
115116
- Language files updated via [#transifex](https://github.com/BornToBeRoot/NETworkManager/pulls?q=author%3Aapp%2Ftransifex-integration)

0 commit comments

Comments
 (0)