# Valgrind "Mismatched new/delete size" not reported as a memory issue

**URL:** <https://discourse.cmake.org/t/valgrind-mismatched-new-delete-size-not-reported-as-a-memory-issue/15740>\
**Category:** Development\
**Tags:** tool:ctest\
**Created:** [July 8, 2026, 3:58pm UTC](https://discourse.cmake.org/t/valgrind-mismatched-new-delete-size-not-reported-as-a-memory-issue/15740 "2026-07-08T15:58:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![npoletz](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/b5ac83/32.png) [@npoletz](https://discourse.cmake.org/u/npoletz)\
**Post date:** [July 8, 2026, 3:58pm UTC](https://discourse.cmake.org/t/valgrind-mismatched-new-delete-size-not-reported-as-a-memory-issue/15740/1 "2026-07-08T15:58:48Z")

</div>

Hello,

I recently encounter a `Mismatched new/delete size value` reported by valgrind but captured by cmake and thus not reported on our dashboard.

The problem seems to be a missing regex in [ProcessMemCheckValgrindOutput](https://gitlab.kitware.com/cmake/cmake/-/blob/v4.3.4/Source/CTest/cmCTestMemCheckHandler.cxx#L929-960) which only reports `R"(== .*Mismatched free\(\) / delete / delete \[\])")` as `Mismatched deallocation`.

Would it be possible to add a specific regex or extend the existing one?

---

<div class="post-metadata">

**Author:** ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)\
**Post date:** [July 8, 2026, 4:01pm UTC](https://discourse.cmake.org/t/valgrind-mismatched-new-delete-size-not-reported-as-a-memory-issue/15740/2 "2026-07-08T16:01:29Z")

</div>

> [@npoletz](#):
>
> Would it be possible to add a specific regex or extend the existing one?

I’d welcome a merge request to do that, yes, thanks.

---

<div class="post-metadata">

**Author:** ![leha-bot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/leha-bot/32/921_2.png) [@leha-bot](https://discourse.cmake.org/u/leha-bot)\
**Post date:** [October 8, 2026, 5:52pm UTC](https://discourse.cmake.org/t/valgrind-mismatched-new-delete-size-not-reported-as-a-memory-issue/15740/3 "2026-10-08T17:52:29Z")

</div>

I made an issue here: [https://gitlab.kitware.com/cmake/cmake/-/work\_items/28149](https://gitlab.kitware.com/cmake/cmake/-/work_items/28149)

The merge request is in progress… @npoletz , may you write a simplest minimal reproducer for this, so I could make a proper unit test please?

---

<div class="post-metadata">

**Author:** ![npoletz](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/b5ac83/32.png) [@npoletz](https://discourse.cmake.org/u/npoletz)\
**Post date:** [October 9, 2026, 7:31am UTC](https://discourse.cmake.org/t/valgrind-mismatched-new-delete-size-not-reported-as-a-memory-issue/15740/4 "2026-10-09T07:31:15Z")

</div>

Hi,  
Thanks for following up. I haven’t had time to fix the issue myself, but I can provide a reproducer. Would you prefer that I post it here or in the issue ?

---

<div class="post-metadata">

**Author:** ![npoletz](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/b5ac83/32.png) [@npoletz](https://discourse.cmake.org/u/npoletz)\
**Post date:** [October 9, 2026, 8:04am UTC](https://discourse.cmake.org/t/valgrind-mismatched-new-delete-size-not-reported-as-a-memory-issue/15740/5 "2026-10-09T08:04:16Z")

</div>

A simple reproducer with a missing virtual dtor is provided below :

```auto
#include <memory>
#include <vector>
#include <iostream>

// Base class with NON-virtual destructor
class Base {
public:
    ~Base() { std::cout << "Base destructor called\n"; }
};

class Derived : public Base {
    int data = 0;
public:
    Derived() : Base()
    {
        std::cout << "Derived constructor\n";
    }

    ~Derived() {
        std::cout << "Derived destructor called\n";
    }
};

int main() {
    
    std::unique_ptr<Base> ptr = std::make_unique< Derived>();
    return 0;
}

```

And gives the following valgrind report:

```auto
==159787== Mismatched new/delete size value: 1
==159787== at 0x484A5B9: operator delete(void*, unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==159787== by 0x109698: std::default_delete<Base>::operator()(Base*) const (unique_ptr.h:99)
==159787== by 0x1094B7: std::unique_ptr<Base, std::default_delete<Base> >::~unique_ptr() (unique_ptr.h:404)
==159787== by 0x109220: main (mismatched_free_delete_reproducer.cpp:27)
==159787== Address 0x4e42080 is 0 bytes inside a block of size 4 alloc'd
==159787== at 0x4846FA3: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==159787== by 0x109318: std:: __detail::_MakeUniq<Derived>::__ single_object std::make_unique<Derived>() (unique_ptr.h:1070)
==159787== by 0x1091F0: main (mismatched_free_delete_reproducer.cpp:25)
==159787== 
==159787== 
==159787== HEAP SUMMARY:
==159787== in use at exit: 0 bytes in 0 blocks
==159787== total heap usage: 3 allocs, 3 frees, 74,756 bytes allocated
==159787== 
==159787== All heap blocks were freed -- no leaks are possible
==159787== 
==159787== For lists of detected and suppressed errors, rerun with: -s
==159787== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

```

---

<div class="post-metadata">

**Author:** ![leha-bot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/leha-bot/32/921_2.png) [@leha-bot](https://discourse.cmake.org/u/leha-bot)\
**Post date:** [October 9, 2026, 8:36am UTC](https://discourse.cmake.org/t/valgrind-mismatched-new-delete-size-not-reported-as-a-memory-issue/15740/6 "2026-10-09T08:36:41Z")

</div>

Thanks, will adopt it as a test case here: [https://gitlab.kitware.com/cmake/cmake/-/work\_items/28149](https://gitlab.kitware.com/cmake/cmake/-/work_items/28149) 👍
