memory issue with C++ wrapper detected by valgrind:

42 views
Skip to first unread message

Basile Starynkevitch

unread,
Mar 18, 2015, 5:53:05 AM3/18/15
to onio...@coralbits.com
Hello all,

I have a prototype program (on Debian/Linux/Sid x86-64, clang 3.5 or gcc 4.9 compiler in C++11 mode) which has the following function:

void ya_web_service(int port)
{
  //DEBUG_OUT("ya_web_service start port=" << port);
  Onion::Onion onionserver(O_THREADED);
  onionserver.setPort(port);
  Onion::Url onionrooturl(&onionserver);
  Onion::ExportLocal onionlocalwebdir("webdir");
  onionrooturl.add("^webdir/", onionlocalwebdir);
  std::cout << "Ya web service on port " << port << std::endl;
  onionserver.listen();
  //DEBUG_OUT("ya_web_service end port=" << port);
}


When I run my program without calling ya_web_service (directly in the middle of main) in a directory having a non-empty webdir/ subdirectory, valgrind is happn (does not detect any leaks in my program not calling ya_web_service).

When I run the same program by passing it -W 8080 as program argument, the only difference is that ya_web_service gets directly called in the middle of my main. Without valgrind, I'm getting

Running the webservice on localhost port 8080 .
[A8C15740] [2015-03-18 10:38:00] [DEBUG onion.c:195] Ignoring SIGPIPE
[A8C15740] [2015-03-18 10:38:00] [DEBUG poller.c:202] Init thread stuff for poll. Eventfd at 5
[A8C15740] [2015-03-18 10:38:00] [DEBUG onion.c:626] add 0xac0cf0 listen_point (0xaaa020, 0xac0cf0, (nil))
[A8C15740] [2015-03-18 10:38:00] [DEBUG onion.c:713] New root url handler
*** Error in `./yacax': double free or corruption (!prev): 0x0000000000abb6d0 ***

and with valgrind I am getting a more precise error:


Running the webservice on localhost port 8080 .
[4063D80] [2015-03-18 10:40:27] [DEBUG onion.c:195] Ignoring SIGPIPE
[4063D80] [2015-03-18 10:40:27] [DEBUG poller.c:202] Init thread stuff for poll. Eventfd at 5
[4063D80] [2015-03-18 10:40:27] [DEBUG onion.c:626] add 0xada70a0 listen_point (0xada71a0, 0xada70a0, (nil))
[4063D80] [2015-03-18 10:40:27] [DEBUG onion.c:713] New root url handler
==5719== Invalid read of size 8
==5719==    at 0x5054AB4: onion_handler_free (handler.c:115)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A24F: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada84a8 is 8 bytes inside a block of size 32 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x5054AF6: onion_handler_free (handler.c:119)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==
==5719== Invalid read of size 8
==5719==    at 0x5054AC1: onion_handler_free (handler.c:115)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A24F: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada84b0 is 16 bytes inside a block of size 32 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x5054AF6: onion_handler_free (handler.c:119)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==
==5719== Invalid read of size 8
==5719==    at 0x5054ACE: onion_handler_free (handler.c:116)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A24F: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada84a8 is 8 bytes inside a block of size 32 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x5054AF6: onion_handler_free (handler.c:119)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==
==5719== Invalid read of size 8
==5719==    at 0x5054AD6: onion_handler_free (handler.c:116)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A24F: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada84b0 is 16 bytes inside a block of size 32 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x5054AF6: onion_handler_free (handler.c:119)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==
==5719== Invalid read of size 8
==5719==    at 0x505CC8A: onion_handler_export_local_delete (exportlocal.c:215)
==5719==    by 0x5054ADE: onion_handler_free (handler.c:116)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A24F: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada8450 is 16 bytes inside a block of size 32 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x505CCA1: onion_handler_export_local_delete (exportlocal.c:216)
==5719==    by 0x5054ADE: onion_handler_free (handler.c:116)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==
==5719== Invalid free() / delete / delete[] / realloc()
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x505CC95: onion_handler_export_local_delete (exportlocal.c:215)
==5719==    by 0x5054ADE: onion_handler_free (handler.c:116)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A24F: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada7400 is 0 bytes inside a block of size 4,096 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x505CC95: onion_handler_export_local_delete (exportlocal.c:215)
==5719==    by 0x5054ADE: onion_handler_free (handler.c:116)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==
==5719== Invalid free() / delete / delete[] / realloc()
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x505CCA1: onion_handler_export_local_delete (exportlocal.c:216)
==5719==    by 0x5054ADE: onion_handler_free (handler.c:116)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A24F: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada8440 is 0 bytes inside a block of size 32 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x505CCA1: onion_handler_export_local_delete (exportlocal.c:216)
==5719==    by 0x5054ADE: onion_handler_free (handler.c:116)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==
==5719== Invalid read of size 8
==5719==    at 0x5054AE3: onion_handler_free (handler.c:118)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A24F: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada84b8 is 24 bytes inside a block of size 32 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x5054AF6: onion_handler_free (handler.c:119)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==
==5719== Invalid free() / delete / delete[] / realloc()
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x5054AF6: onion_handler_free (handler.c:119)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A24F: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada84a0 is 0 bytes inside a block of size 32 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x5054AF6: onion_handler_free (handler.c:119)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==
==5719== Invalid read of size 8
==5719==    at 0x5054AB4: onion_handler_free (handler.c:115)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x47A25B: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada84a8 is 8 bytes inside a block of size 32 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x5054AF6: onion_handler_free (handler.c:119)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==
==5719== Invalid read of size 8
==5719==    at 0x5054AC1: onion_handler_free (handler.c:115)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x47A25B: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada84b0 is 16 bytes inside a block of size 32 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x5054AF6: onion_handler_free (handler.c:119)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==
==5719== Invalid read of size 8
==5719==    at 0x5054ACE: onion_handler_free (handler.c:116)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x47A25B: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada84a8 is 8 bytes inside a block of size 32 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x5054AF6: onion_handler_free (handler.c:119)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==
==5719== Invalid read of size 8
==5719==    at 0x5054AD6: onion_handler_free (handler.c:116)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x47A25B: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada84b0 is 16 bytes inside a block of size 32 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x5054AF6: onion_handler_free (handler.c:119)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==
==5719== Invalid read of size 8
==5719==    at 0x505CC8A: onion_handler_export_local_delete (exportlocal.c:215)
==5719==    by 0x5054ADE: onion_handler_free (handler.c:116)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x47A25B: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada8450 is 16 bytes inside a block of size 32 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x505CCA1: onion_handler_export_local_delete (exportlocal.c:216)
==5719==    by 0x5054ADE: onion_handler_free (handler.c:116)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==
==5719== Invalid read of size 8
==5719==    at 0x5054AE3: onion_handler_free (handler.c:118)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x47A25B: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==  Address 0xada84b8 is 24 bytes inside a block of size 32 free'd
==5719==    at 0x4C29E90: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==5719==    by 0x5051BF6: onion_low_free (low.c:226)
==5719==    by 0x5054AF6: onion_handler_free (handler.c:119)
==5719==    by 0x4E406F1: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:56)
==5719==    by 0x4E4072D: Onion::ExportLocal::~ExportLocal() (shortcuts.cpp:57)
==5719==    by 0x47A9B4: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_destroy(std::_Any_data&, std::integral_constant<bool, false>) (functional:1894)
==5719==    by 0x47A872: std::_Function_base::_Base_manager<Onion::ExportLocal>::_M_manager(std::_Any_data&, std::_Any_data const&, std::_Manager_operation) (functional:1918)
==5719==    by 0x475286: std::_Function_base::~_Function_base() (functional:1998)
==5719==    by 0x47A6A4: std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>::~function() (functional:1834)
==5719==    by 0x47A528: Onion::Url::add(std::string const&, std::function<onion_connection_status_e (Onion::Request&, Onion::Response&)>) (url.hpp:119)
==5719==    by 0x47A23A: ya_web_service(int) (ywebx.cc:15)
==5719==    by 0x497B4B: main (ymainx.cc:159)
==5719==
Ya web service on port 8080
[4063D80] [2015-03-18 10:40:27] [DEBUG listen_point.c:186] Trying to listen at (null):8080
[4063D80] [2015-03-18 10:40:27] [DEBUG listen_point.c:227] Listening to 0.0.0.0:8080, fd 6
[4063D80] [2015-03-18 10:40:27] [DEBUG onion.c:484] Adding listen point fd 6 to poller
[4063D80] [2015-03-18 10:40:27] [DEBUG onion.c:492] Start polling / listening 0xada71a0, 0xada70a0, (nil)
[C92B700] [2015-03-18 10:40:27] [DEBUG poller.c:356] Start polling
[C12A700] [2015-03-18 10:40:27] [DEBUG poller.c:356] Start polling
[B929700] [2015-03-18 10:40:27] [DEBUG poller.c:356] Start polling
[D92D700] [2015-03-18 10:40:27] [DEBUG poller.c:356] Start polling
[E92F700] [2015-03-18 10:40:27] [DEBUG poller.c:356] Start polling
[D12C700] [2015-03-18 10:40:27] [DEBUG poller.c:356] Start polling
[E12E700] [2015-03-18 10:40:27] [DEBUG poller.c:356] Start polling
[4063D80] [2015-03-18 10:40:27] [DEBUG poller.c:356] Start polling



Some more details: my main does not use any Onion thing except (where int webport; is some local main variable previously initialized by command line parsing with getopt_long...) in a middle block which contains


  if (webport>0)
    {
      std::cout << "Running the webservice on localhost port "
                << webport << " ." << std::endl;
      ya_web_service(webport);
      std::cout  << std::endl << "Done webservice." << std::endl;
    }



I just recompiled and reinstalled the libonion from David Moreno's github: git log | head says

commit 25d4a2ad8cb6bd4e193ba69589fe7ad8674c2f57
Merge: 5c97f90 2987064
Author: David Moreno Montero <dmo...@coralbits.com>
Date:   Mon Jan 26 15:21:56 2015 +0100

    Merge pull request #102 from bstarynk/master
   
    more systematic testing of listen point reader & writer to avoid core dump

commit 2987064881e773a9637b351a28baf8923763eb78


I believe I am incorrectly understanding how to use onion with C++11 (or C++14) or  have found a bug in libonion C++ ; any clues?

Regards.

--
Basile Starynkevitch (France)      http://starynkevitch.net/Basile/

Basile Starynkevitch

unread,
Mar 18, 2015, 6:06:45 AM3/18/15
to onio...@coralbits.com

The following selfcontained example reproduces the bug:

// file testonion.cc
#include <iostream>
#include <string>
#include "onion/onion.hpp"
#include "onion/response.hpp"
#include "onion/url.hpp"
#include "onion/shortcuts.hpp"

void ya_web_service(int port)

{
  Onion::Onion onionserver(O_THREADED);
  onionserver.setPort(port);
  Onion::Url onionrooturl(&onionserver);
  Onion::ExportLocal onionlocalwebdir("webdir");
  onionrooturl.add("^webdir/", onionlocalwebdir);
  std::cout << "Ya web service on port " << port << std::endl;
  onionserver.listen();
}

int main (int argc, char** argv)
{
  int portnum = (argc>1) ? std::stoi(argv[1]):8080;
  ya_web_service(portnum);
  std::cout << "end of main" << std::endl;
  return 0;
}


Compile it as cd ~/tmp/; g++ -std=c++11 -Wall -g -I /usr/local testonion.cc -o testonion -L/usr/local -lonioncpp -lonion

then run it in a directory having a webdir/ subdirectory having some webdir/index.html file

Basile Starynkevitch

unread,
Mar 18, 2015, 6:14:54 AM3/18/15
to onio...@coralbits.com

Added on github the new issue 105

David Moreno Montero

unread,
Mar 18, 2015, 6:29:22 AM3/18/15
to Basile Starynkevitch, onion-dev
Thanks for adding the bug report. I will have a look ASAP.

2015-03-18 11:14 GMT+01:00 Basile Starynkevitch <bas...@starynkevitch.net>:

Added on github the new issue 105

--
You received this message because you are subscribed to the Google Groups "onion-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to onion-dev+...@coralbits.com.
To post to this group, send email to onio...@coralbits.com.
Visit this group at http://groups.google.com/a/coralbits.com/group/onion-dev/.
For more options, visit https://groups.google.com/a/coralbits.com/d/optout.



--

Basile Starynkevitch

unread,
Mar 18, 2015, 10:32:30 AM3/18/15
to onio...@coralbits.com, bas...@starynkevitch.net


On Wednesday, March 18, 2015 at 11:29:22 AM UTC+1, David Moreno Montero wrote:
Thanks for adding the bug report. I will have a look ASAP.


What kind of C++ are you aiming? It looks (since you are using anonymous lambda functions in example) that you are targeting only C++11 or better (no C++98).

Then, is there any reason why you don't use smart pointers ? That is include <memory> and use std::shared_ptr (or maybe std::unique_ptr)? They can accept a custom Deleter!

Cheers.

Basile Starynkevitch

unread,
Mar 18, 2015, 10:36:07 AM3/18/15
to onio...@coralbits.com, bas...@starynkevitch.net


On Wednesday, March 18, 2015 at 3:32:30 PM UTC+1, Basile Starynkevitch wrote:
Then, is there any reason why you don't use smart pointers ? That is include <memory> and use std::shared_ptr (or maybe std::unique_ptr)? They can accept a custom Deleter!

Otherwise, you need to implement manually the C++11 rule of five

David Moreno Montero

unread,
Mar 19, 2015, 6:10:41 AM3/19/15
to Basile Starynkevitch, onion-dev
Hi,

Im checking it now, but the problem is a bit deeper than reference counting on the C++ side. At least it requires removal of handlers on the C side.

Anyway fixing it now.

At the begining it was C++98 compatible to support some old compilers, but I think its time to require and enjoy C++11.

Regards,
David

--
You received this message because you are subscribed to the Google Groups "onion-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to onion-dev+...@coralbits.com.
To post to this group, send email to onio...@coralbits.com.
Visit this group at http://groups.google.com/a/coralbits.com/group/onion-dev/.
For more options, visit https://groups.google.com/a/coralbits.com/d/optout.

Basile Starynkevitch

unread,
Mar 19, 2015, 8:09:13 AM3/19/15
to onio...@coralbits.com, bas...@starynkevitch.net

At the begining it was C++98 compatible to support some old compilers, but I think its time to require and enjoy C++11.

But you are using C++11 lambda functions  in your examples/cpp/main.cpp file (the only C++ example), so you are already requiring C++11 ....

    root.add("lambda", [](Onion::Request &req, Onion::Response &res){
        res<<"Lambda handler";
        return OCS_PROCESSED;
    });

and I am happy with that. Of course, if you want to support both C++11 and some older standard (e.g. C++98), it is more work for you. IMHO, it is not worth the pain in 2015. I view C++11 as a different language than C++98 (or C99 or C11).

Cheers.

Basile Starynkevitch

unread,
Mar 20, 2015, 4:47:02 AM3/20/15
to onio...@coralbits.com, bas...@starynkevitch.net


On Thursday, March 19, 2015 at 11:10:41 AM UTC+1, David Moreno Montero wrote:
Hi,

Im checking it now, but the problem is a bit deeper than reference counting on the C++ side. At least it requires removal of handlers on the C side.

 Regarding your latest f5242ae4e1b7... commit to the cppnext branch, I added the following comments:

typo in the comment in 03-urls.cpp ; must me freed -> must be freed

You really should add a comment about the owner boolean flag. What about multi-threaded applications and "concurrent" -i.e. multi-threaded- accesses to instances of Onion::Onion, Onion::Handler, Onion::Url etc etc? C++11 seems to have a more precise ownership concept (with its several smart pointers template classes).

Perhaps, because of multi-threading issues, owner should be a std::atomic<size_t> reference counter, then why not just use standard C++ std::shared_ptr. Please document how to use Onion C++ in a multi-threaded C++11 application (on a Linux system, where C++11 threads are interoperable with Linux pthreads) and what is the user of Onion C++ is permitted or forbidden to code in a multi-threaded application using Onion.

(I still got the intuition that using C++11 smart pointers is preferable, and you should care about the C++ rule of five I have previously mentioned)

Reply all
Reply to author
Forward
0 new messages