Menu ▾ ▴

FALSE NEGATIVE: Mismatched deletion through an object member is missed

Rodri
2026-09-14
2026-09-15
  • Rodri

    Rodri - 2026-09-14

    Hi, I found a false negative in Cppcheck 2.21.0 when a pointer allocated by scalar new is stored in an object member and released with delete[].

    Affected tool

    Cppcheck 2.21.0

    Affected checker

    mismatchAllocDealloc

    Minimal reproducer

    struct Owner {
      int *data;
    };
    
    void test() {
      Owner owner;
      owner.data = new int;
      delete[] owner.data;
    }
    

    Reproduction command

    cppcheck --version
    cppcheck --enable=warning --inconclusive --check-level=exhaustive --std=c++17 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' mutant-cppcheck-mismatchallocdealloc-fn-object-member.cpp
    

    Current behavior

    Cppcheck emits no mismatchAllocDealloc diagnostic. Its checker report confirms that the warning configuration is active.

    Expected behavior

    Cppcheck should report that owner.data, allocated by scalar new, is incorrectly released by delete[].

     
  • CHR

    CHR - 2026-09-15

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15036

     

Log in to post a comment.