Skip to content

Fix memory leak in LLVMFuzzerTestOneInput when Initialize() fails#5202

Merged
guhetier merged 3 commits into
mainfrom
copilot/fix-5201
Jul 9, 2025
Merged

Fix memory leak in LLVMFuzzerTestOneInput when Initialize() fails#5202
guhetier merged 3 commits into
mainfrom
copilot/fix-5201

Conversation

Copilot AI commented Jun 30, 2025

Copy link
Copy Markdown
Contributor

This PR fixes a memory leak in the LLVMFuzzerTestOneInput function in src/tools/spin/spinquic.cpp.

Issue:
When FuzzData->Initialize() returns false, the function exits early without deallocating the FuzzData object that was allocated with new, causing a memory leak on every such input.

Root Cause:

FuzzData = new FuzzingData(data, size);  // Line 1602: Memory allocated
if (!FuzzData->Initialize()) {
    return 0;  // Line 1604: Early return without cleanup - LEAK!
}

Fix:
Added delete FuzzData; before the early return to ensure proper cleanup:

FuzzData = new FuzzingData(data, size);
if (!FuzzData->Initialize()) {
    delete FuzzData;  // Added: Properly clean up allocated memory
    return 0;
}

Verification:

  • ✅ Build passes successfully with the fix
  • ✅ Pattern is consistent with existing code (normal execution path also calls delete FuzzData; at the end)
  • ✅ Minimal change (1 line added) that precisely addresses the issue
  • ✅ Compared with similar fuzzing code in recvfuzz.cpp which doesn't have this issue due to simpler constructor pattern

Fixes #5201.


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

Co-authored-by: guhetier <15261469+guhetier@users.noreply.github.com>
Copilot AI changed the title [WIP] Potential memory leak in LLVMFuzzerTestOneInput When Initialization Fails Fix memory leak in LLVMFuzzerTestOneInput when Initialize() fails Jun 30, 2025
Copilot AI requested a review from guhetier June 30, 2025 17:35
@guhetier
guhetier marked this pull request as ready for review June 30, 2025 18:05
@guhetier
guhetier requested a review from a team as a code owner June 30, 2025 18:05
nibanks
nibanks previously approved these changes Jul 1, 2025
@guhetier

guhetier commented Jul 1, 2025

Copy link
Copy Markdown
Collaborator
[BVT / BVT (Debug, linux, ubuntu-22.04, x64, quictls, -Sanitize, -Test) (pull_request)](https://github.com/microsoft/msquic/actions/runs/15979720574/job/45073476333?pr=5202)Failing after 54m

This test seems to have consistently regressed recently. It isn't specific to this PR though.

mtfriesen
mtfriesen previously approved these changes Jul 7, 2025
Comment thread src/tools/spin/spinquic.cpp Outdated
Co-authored-by: mtfriesen <3517159+mtfriesen@users.noreply.github.com>
Copilot AI dismissed stale reviews from mtfriesen and nibanks via 1fe3bce July 7, 2025 20:21
Copilot AI requested a review from mtfriesen July 7, 2025 20:22
@codecov

codecov Bot commented Jul 8, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.23%. Comparing base (c69379c) to head (1fe3bce).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5202      +/-   ##
==========================================
+ Coverage   85.53%   86.23%   +0.69%     
==========================================
  Files          59       59              
  Lines       18330    18330              
==========================================
+ Hits        15679    15807     +128     
+ Misses       2651     2523     -128     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@guhetier
guhetier merged commit 75f8235 into main Jul 9, 2025
485 of 492 checks passed
@guhetier
guhetier deleted the copilot/fix-5201 branch July 9, 2025 16:07
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.

Potential memory leak in LLVMFuzzerTestOneInput When Initialization Fails

4 participants