GCC 8.1.0 STL vs Valgrind

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all.  I have no idea if this is my code or not, or even if the
question belongs here, but thought I'd start here just in case.

We recently upgraded from GCC 6.2 to GCC 8.1 (GNU/Linux, 64bit).  These
are instances of GCC I've compiled myself from source with appropriate
binutils etc.

In our Valgrind testing since the change we've seen thousands and
thousands of new errors about mismatched free / delete / delete []. 
All of them appear to be emitted from STL allocations.  For example:

==30514== Mismatched free() / delete / delete []
==30514==    at 0x4C30C9B: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==30514==    by 0x5E617B: deallocate (new_allocator.h:125)
==30514==    by 0x5E617B: deallocate (alloc_traits.h:462)
==30514==    by 0x5E617B: _M_deallocate (stl_vector.h:304)
==30514==    by 0x5E617B: void std::vector<...
  ...
==30514==  Address 0x80d37c0 is 0 bytes inside a block of size 8 alloc'd
==30514==    at 0x4C3017F: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==30514==    by 0x5E60DB: allocate (new_allocator.h:111)
==30514==    by 0x5E60DB: allocate (alloc_traits.h:436)
==30514==    by 0x5E60DB: _M_allocate (stl_vector.h:296)
==30514==    by 0x5E60DB: void std::vector<...
  ...

I can't explain why the deallocate() in new_allocator.h:125:

      void
      deallocate(pointer __p, size_type)
      {
#if __cpp_aligned_new
        if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
          {
            ::operator delete(__p, std::align_val_t(alignof(_Tp)));
            return;
          }
#endif
        ::operator delete(__p);
      }

should be interpreted as invoking valgrind's free(), while the
allocate() in that same file at line 111:

      pointer
      allocate(size_type __n, const void* = static_cast<const void*>(0))
      {
        if (__n > this->max_size())
          std::__throw_bad_alloc();

#if __cpp_aligned_new
        if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
          {
            std::align_val_t __al = std::align_val_t(alignof(_Tp));
            return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), __al));
          }
#endif
        return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp)));
      }

is seen as invoking valgrind's operator new implementation rather than
malloc.

This is the standard valgrind that comes with Ubuntu 18.04 (3.13) but
I've also tried with older 3.9 and 3.11 with the same results.

I have no explanation and maybe it's a valgrind issue, but the only
thing that changed here was GCC.  I've googled around but no joy from
any information I found (most of which dates back to 2009 or earlier). 
If anyone has a tip I'm interested.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux