Bug 469606

Summary: valgrind crashed when compile with c++ stand 17 and boost::lockfree::queue
Product: [Developer tools] valgrind Reporter: Luke <lvwanzhu2008>
Component: massifAssignee: Nicholas Nethercote <njn>
Status: RESOLVED NOT A BUG    
Severity: crash CC: pjfloyd
Priority: NOR    
Version First Reported In: 3.16.1   
Target Milestone: ---   
Platform: RedHat Enterprise Linux   
OS: Unspecified   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Luke 2023-05-11 03:37:07 UTC
SUMMARY
***
NOTE: If you are reporting a crash, please try to attach a backtrace with debug symbols.
See https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***


STEPS TO REPRODUCE
1.  compile project with flag "-std=c++17"
2.  run application with valgrind massif tool

OBSERVED RESULT
valgrind/massif crashed with below error:
==16638== Massif, a heap profiler
==16638== Copyright (C) 2003-2017, and GNU GPL'd, by Nicholas Nethercote
==16638== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==16638== Command: /build/os/sys-root/x86_64-pc-linux-gnu/lib64/ld-linux-x86-64.so.2 --library-path /build/os/sys-root/x86_64-pc-linux-gnu/lib64 myapp
==16638==
Starting main...
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
==16638==
==16638== Process terminating with default action of signal 6 (SIGABRT): dumping core
==16638==    at 0x5A3A610: raise (raise.c:50)
==16638==    by 0x5A24525: abort (abort.c:79)
==16638==    by 0x576D80B: ??? (in /build/os/sys-root/x86_64-pc-linux-gnu/usr/lib64/libstdc++.so.6.0.28)
==16638==    by 0x57788F5: ??? (in /build/os/sys-root/x86_64-pc-linux-gnu/usr/lib64/libstdc++.so.6.0.28)
==16638==    by 0x5778960: std::terminate() (in /build/os/sys-root/x86_64-pc-linux-gnu/usr/lib64/libstdc++.so.6.0.28)
==16638==    by 0x5778BF3: __cxa_throw (in /build/os/sys-root/x86_64-pc-linux-gnu/usr/lib64/libstdc++.so.6.0.28)
==16638==    by 0x576D4C7: ??? (in /build/os/sys-root/x86_64-pc-linux-gnu/usr/lib64/libstdc++.so.6.0.28)
==16638==    by 0xD63ECE: allocate (new_allocator.h:112)
==16638==    by 0xD63ECE: freelist_stack<std::allocator<boost::lockfree::queue<std::function<void(int)>*>::node> > (freelist.hpp:61)
==16638==    by 0xD63ECE: boost::lockfree::queue<std::function<void (int)>*>::queue(unsigned long) (queue.hpp:217)


code example:

TaskPool::TaskPool()
    : tasksQueue_(100)
{
}

mutable boost::lockfree::queue<std::function<void(int id)>* > tasksQueue_;

EXPECTED RESULT
no crash

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma:  
N.el7.x86_64 #2 SMP Mon Nov 30 18:39:13 EET 2020 x86_64 x86_64 x86_64 GNU/Linux
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
If I compile project with flag "-std=c++14", valgrind works correctly.
Comment 1 Paul Floyd 2023-05-11 06:51:45 UTC
==16638== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info

Most likely that is your problem - a Valgrind that is 4 versions out of date.

The above version does not include

commit e42badd060c789fe712a13d4c3ff8360a44d60f3
Author: Paul Floyd <pjfloyd@wanadoo.fr>
Date:   Tue Mar 2 13:32:22 2021 +0100

    Bug 388787 - Support for C++17 new/delete
    
    These over-aligned new and delete operators were added in C++ 17.

Could you try again with the latest Valgrind?
Comment 2 Luke 2023-05-12 06:03:37 UTC
Indeed it's my own problem, after upgrade valgrind to 3.22 everything works.
thanks Paul Floyd for your help.