Skip to content

dev/cppcheck: add minimal reproducer for memleakOnRealloc false positive#36

Draft
Copilot wants to merge 3 commits into
masterfrom
copilot/create-minimal-false-positive-poc
Draft

dev/cppcheck: add minimal reproducer for memleakOnRealloc false positive#36
Copilot wants to merge 3 commits into
masterfrom
copilot/create-minimal-false-positive-poc

Conversation

Copy link
Copy Markdown

Copilot AI commented May 3, 2026

cppcheck incorrectly reports [memleakOnRealloc] in src/quic_rx.c:819 (qc_try_store_new_token) because it doesn't track that a local copy of a struct-held pointer preserves the original allocation through the failure path.

Changes

  • dev/cppcheck/cppcheck_test.c — self-contained C file (no haproxy headers) that reproduces the false positive with stripped-down types mirroring the original pattern:
local_ptr = buf_ptr(*b);          // local copy of b->ptr
if (len > buf_len(*b)) {
    local_ptr = realloc(local_ptr, len);  // cppcheck fires here
    if (local_ptr)
        b->ptr = local_ptr;
    else {
        memset(buf_ptr(*b), 0, buf_len(*b));
        buf_free(b);              // b->ptr still valid, correctly freed
    }
}

cppcheck sees local_ptr nulled on realloc failure and assumes the original allocation is lost, not realising b->ptr still holds it and the else branch frees it. The file is ready to submit as a cppcheck upstream bug report.

chipitsine and others added 2 commits April 25, 2026 12:59
fixes haproxy#2124

src/cpuset.c:21:11: error: Found an exit path from function with non-void return type that has missing return statement [missingReturn]
src/cpuset.c:36:11: error: Found an exit path from function with non-void return type that has missing return statement [missingReturn]
src/cpuset.c:100:1: error: Found an exit path from function with non-void return type that has missing return statement [missingReturn]
src/cpuset.c:124:1: error: Found an exit path from function with non-void return type that has missing return statement [missingReturn]
src/cpuset.c:152:1: error: Found an exit path from function with non-void return type that has missing return statement [missingReturn]
src/cpuset.c:163:1: error: Found an exit path from function with non-void return type that has missing return statement [missingReturn]
Copilot AI linked an issue May 3, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Create minimal reproducer for cppcheck false positive dev/cppcheck: add minimal reproducer for memleakOnRealloc false positive May 3, 2026
Copilot AI requested a review from chipitsine May 3, 2026 08:07
@chipitsine chipitsine force-pushed the master branch 2 times, most recently from a9066f4 to c090e51 Compare May 13, 2026 15:09
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.

create minimal false positive poc

2 participants