chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.72k stars 1.19k forks source link

callback_wrapper.cpp example fails with Electric Fence #1453

Closed OleStauning closed 3 months ago

OleStauning commented 3 months ago

I have installed boost 1.85.0 and am testing the callback_wrapper example on Ubuntu 22.04.3 LTS:

https://think-async.com/Asio/boost_asio_1_28_0/doc/html/boost_asio/example/cpp20/operations/callback_wrapper.cpp

compiling with electic fence:

$ g++-12 -g -std=c++20 -c -o callback_wrapper.o callback_wrapper.cpp $ g++-12 -g -std=c++20 -o callback_wrapper callback_wrapper.o -lefence

running with electric fence gives an error:

$ ./callback_wrapper 

  Electric Fence 2.2 Copyright (C) 1987-1999 Bruce Perens <bruce@perens.com>
Enter your name: test
Hello test

ElectricFence Aborting: free(5722980a22a0): address not from malloc().
Illegal instruction (core dumped)

Loading the core dump into gdb gives the following stack-trace

Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./callback_wrapper'.
Program terminated with signal SIGILL, Illegal instruction.
#0  0x0000771f7084275b in kill () at ../sysdeps/unix/syscall-template.S:120
120     ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) bt
#0  0x0000771f7084275b in kill () at ../sysdeps/unix/syscall-template.S:120
#1  0x0000771f70ee9607 in ?? () from /lib/libefence.so.0
#2  0x0000771f70ee971f in EF_Abortv () from /lib/libefence.so.0
#3  0x0000771f70ee97bd in EF_Abort () from /lib/libefence.so.0
#4  0x0000771f70ee872a in ?? () from /lib/libefence.so.0
#5  0x0000771f70ee9134 in free () from /lib/libefence.so.0
#6  0x000061b0def79e54 in boost::asio::aligned_delete (ptr=0x61b0e0f302a0) at /usr/local/include/boost/asio/detail/memory.hpp:115
#7  0x000061b0def79f88 in boost::asio::detail::thread_info_base::~thread_info_base (this=0x7ffe94dcfc00, __in_chrg=<optimized out>) at /usr/local/include/boost/asio/detail/thread_info_base.hpp:112
#8  0x000061b0def7ef2e in boost::asio::detail::scheduler_thread_info::~scheduler_thread_info (this=0x7ffe94dcfc00, __in_chrg=<optimized out>) at /usr/local/include/boost/asio/detail/scheduler_thread_info.hpp:30
#9  0x000061b0def7f0b7 in boost::asio::detail::scheduler::run (this=0x771f70716f00, ec=...) at /usr/local/include/boost/asio/detail/impl/scheduler.ipp:214
#10 0x000061b0def7f9ab in boost::asio::io_context::run (this=0x7ffe94dcfd20) at /usr/local/include/boost/asio/impl/io_context.ipp:64
#11 0x000061b0def74e98 in test_callback () at callback_wrapper.cpp:106
#12 0x000061b0def75247 in main () at callback_wrapper.cpp:151

Is this an error in electric fence or boost asio ?

With best regards,

OleStauning commented 3 months ago

It seems to be electric fence that are having issues with std::aligned_alloc allocations.