Fix memory leak in PerfServer DelayWorker initialization failure#5213
Merged
Conversation
Co-authored-by: guhetier <15261469+guhetier@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Potential Memory Leak on DelayWorker Initialization Failure
Fix memory leak in PerfServer DelayWorker initialization failure
Jul 1, 2025
guhetier
marked this pull request as ready for review
July 1, 2025 16:29
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5213 +/- ##
==========================================
- Coverage 86.74% 85.64% -1.11%
==========================================
Files 59 59
Lines 18330 18330
==========================================
- Hits 15901 15698 -203
- Misses 2429 2632 +203 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
csujedihy
reviewed
Jul 1, 2025
Co-authored-by: csujedihy <6022514+csujedihy@users.noreply.github.com>
csujedihy
approved these changes
Jul 1, 2025
guhetier
approved these changes
Jul 1, 2025
nibanks
approved these changes
Jul 2, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In
PerfServer::Init(), whenDelayWorkers[i].Initialize()fails during the initialization loop, the function returnsQUIC_STATUS_INTERNAL_ERRORwithout cleaning up the already allocatedDelayWorkersarray, causing a memory leak.The problematic code:
Solution
This PR implements a comprehensive fix that addresses both the reported issue and additional edge cases:
new (std::nothrow)to handle allocation failure gracefullyShutdown()on all DelayWorkers (safe for both initialized and uninitialized workers)delete[] DelayWorkersDelayWorkers = nullptrQUIC_STATUS_OUT_OF_MEMORYfor allocation failure,QUIC_STATUS_INTERNAL_ERRORfor initialization failureChanges Made
Verification
Created and tested a mock implementation that simulates the initialization failure scenario, confirming that:
Shutdown()The fix is more comprehensive than the original suggestion as it also handles allocation failure and follows the existing destructor cleanup pattern for consistency.
Fixes #5206.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.