Menu ▾ ▴

FALSE NEGATIVE: Indexed member access hides a mismatched `delete[]`

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

    Rodri - 2026-09-14

    Hi, I found a false negative in Cppcheck 2.21.0 when an indexed member access occurs between a scalar allocation and mismatched array deletion.

    Affected tool

    Cppcheck 2.21.0

    Affected checker

    mismatchAllocDealloc

    Minimal reproducer

    struct Item {
      int value;
    };
    
    void test() {
      Item *item = new Item;
      item[0].value = 0;
      delete[] item;
    }
    

    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-indexed-member-before-delete.cpp
    

    Current behavior

    Cppcheck emits no mismatchAllocDealloc diagnostic. Its checker report confirms that the warning configuration is active. Removing the indexed member access makes Cppcheck report the mismatch.

    Expected behavior

    Cppcheck should report that item, 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/15035

     

Log in to post a comment.