[Ovmsdev] A promiscous wifi client

Stephen Casner casner at acm.org
Thu Nov 16 10:33:44 HKT 2017


On Wed, 15 Nov 2017, Stephen Casner wrote:

> Originally the TelnetServer task was a direct child of the wifi task
> (using the Parent and TaskBase classes I created) and the wifi task
> would do the deletion.  Subsequently we've changed to use events and
> the cleanup is not working properly.  In fact, now when I command wifi
> down the system always restarts immediately because the heap debug
> code is detecting that a block is freed twice.  I need to investigate
> further.  Using multiple tasks is tricky because these libraries are
> not all thread-safe so we have to be very careful to execute code in
> the right task.

This double-free is happening in the SSH server, not Telnet, so if you
don't have SSH configured you won't hit it.  I'll be changing Telnet
to also be a configurable component shortly, as Mark requested a few
days ago.

The reason the system was restarting immediately rather than crashing
on an abort to give a stack trace is that the code was trying to do a
mem_malloc_show() to list all the blocks.  There are too many blocks
so the watchdog timed out and restarted the system.

Commenting out the mem_malloc_show() allows me to get the GDB stack
backtrace for this double-free as shown below so I can debug this.
That is one deep stack!  I wish FreeRTOS had a nice, clean
message-passing signal/wait mechanism for IPC like the real-time OS I
helped to write for the PDP-11 in 1975...

                                                        -- Steve

#0  0x40088d54 in invoke_abort () at /Users/casner/src/github/esp-idf/components/esp32/./panic.c:125
#1  0x40088e22 in abort () at /Users/casner/src/github/esp-idf/components/esp32/./panic.c:134
#2  0x40085b6f in mem_free_block (data=0x3fff270c) at /Users/casner/src/github/esp-idf/components/freertos/./heap_regions_debug.c:335
#3  0x400854bb in vPortFreeTagged (pv=0x3fff2714) at /Users/casner/src/github/esp-idf/components/freertos/./heap_regions.c:362
#4  0x400893c8 in vPortFree (pv=0x3fff2714) at /Users/casner/src/github/esp-idf/components/esp32/./heap_alloc_caps.c:323
#5  0x40081fbc in _free_r (r=0x3ffe6ec8, ptr=0x3fff2714) at /Users/casner/src/github/esp-idf/components/newlib/./syscalls.c:32
#6  0x4000beca in ?? ()
#7  0x400d2ec8 in PwMapListDelete (list=<optimized out>) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/components/console_ssh/src/console_ssh.cpp:614
#8  0x400d2ed9 in SSHServer::Cleanup (this=0x3ffe7fc8) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/components/console_ssh/src/console_ssh.cpp:293
#9  0x400d2f42 in SSHServer::~SSHServer (this=0x3ffe7fc8, __in_chrg=<optimized out>) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/components/console_ssh/src/console_ssh.cpp:197
#10 0x400d2f59 in SSHServer::~SSHServer (this=0x3ffe7fc8, __in_chrg=<optimized out>) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/components/console_ssh/src/console_ssh.cpp:198
#11 0x40130a51 in TaskBase::DeleteTask (this=0x3ffe7fc8) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./task_base.cpp:162
#12 0x40130b14 in Parent::DeleteChildren (this=0x3ffc2d58 <MySSH>) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./task_base.cpp:100
#13 0x400d2c40 in OvmsSSH::WifiDown (this=0x3ffc2d58 <MySSH>, event=..., data=0x0) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/components/console_ssh/src/console_ssh.cpp:171
#14 0x400d3997 in std::_Mem_fn_base<void (OvmsSSH::*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*), true>::operator()<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*, void>(OvmsSSH*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, void*&&) const (__object=<optimized out>, this=<optimized out>) at /Users/casner/src/github/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:600
#15 std::_Bind<std::_Mem_fn<void (OvmsSSH::*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*)> (OvmsSSH*, std::_Placeholder<1>, std::_Placeholder<2>)>::__call<void, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, void*&&, 0u, 1u, 2u>(std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, void*&&>&&, std::_Index_tuple<0u, 1u, 2u>) (__args=<unknown type in /Users/casner/src/github/ovms/vehicle/OVMS.V3/build/ovms3.elf, CU 0x6c4b, DIE 0x13599>, this=<optimized out>) at /Users/casner/src/github/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1074
#16 std::_Bind<std::_Mem_fn<void (OvmsSSH::*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*)> (OvmsSSH*, std::_Placeholder<1>, std::_Placeholder<2>)>::operator()<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*, void>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, void*&&) (this=<optimized out>) at /Users/casner/src/github/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1133
#17 std::_Function_handler<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*), std::_Bind<std::_Mem_fn<void (OvmsSSH::*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*)> (OvmsSSH*, std::_Placeholder<1>, std::_Placeholder<2>)> >::_M_invoke(std::_Any_data const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, void*&&) (__functor=..., __args#0=<optimized out>, __args#1=<optimized out>) at /Users/casner/src/github/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1871
#18 0x4012936c in std::function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*)>::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*) const (this=0x3ffcf01c, __args#0=..., __args#1=0x0) at /Users/casner/src/github/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:2271
#19 0x401297f8 in OvmsEvents::SignalEvent (this=<optimized out>, event=..., data=0x0) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./ovms_events.cpp:112
#20 0x4012ebc3 in OvmsNetManager::WifiDown (this=0x3ffc4570 <MyNetManager>, event=..., data=0x0) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./ovms_netmanager.cpp:91
#21 0x4012f22b in std::_Mem_fn_base<void (OvmsNetManager::*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*), true>::operator()<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*, void>(OvmsNetManager*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, void*&&) const (__object=<optimized out>, this=<optimized out>) at /Users/casner/src/github/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:600
#22 std::_Bind<std::_Mem_fn<void (OvmsNetManager::*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*)> (OvmsNetManager*, std::_Placeholder<1>, std::_Placeholder<2>)>::__call<void, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, void*&&, 0u, 1u, 2u>(std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, void*&&>&&, std::_Index_tuple<0u, 1u, 2u>) (__args=<unknown type in /Users/casner/src/github/ovms/vehicle/OVMS.V3/build/ovms3.elf, CU 0x324256, DIE 0x331cb6>, this=<optimized out>) at /Users/casner/src/github/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1074
#23 std::_Bind<std::_Mem_fn<void (OvmsNetManager::*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*)> (OvmsNetManager*, std::_Placeholder<1>, std::_Placeholder<2>)>::operator()<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*, void>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, void*&&) (this=<optimized out>) at /Users/casner/src/github/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1133
#24 std::_Function_handler<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*), std::_Bind<std::_Mem_fn<void (OvmsNetManager::*)(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*)> (OvmsNetManager*, std::_Placeholder<1>, std::_Placeholder<2>)> >::_M_invoke(std::_Any_data const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, void*&&) (__functor=..., __args#0=<optimized out>, __args#1=<optimized out>) at /Users/casner/src/github/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:1871
#25 0x4012936c in std::function<void (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*)>::operator()(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, void*) const (this=0x3ffcfce0, __args#0=..., __args#1=0x0) at /Users/casner/src/github/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/5.2.0/functional:2271
#26 0x401297f8 in OvmsEvents::SignalEvent (this=<optimized out>, event=..., data=0x0) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./ovms_events.cpp:112
#27 0x400d6216 in esp32wifi::StopStation (this=0x3ffdca50) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/components/esp32wifi/./esp32wifi.cpp:308
#28 0x400d629e in wifi_mode_off (verbosity=<optimized out>, writer=0x3ffe4360, cmd=0x3ffce8fc, argc=0, argv=0x0) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/components/esp32wifi/./esp32wifi.cpp:130
#29 0x40127115 in OvmsCommand::Execute (this=0x3ffce8fc, verbosity=65535, writer=0x3ffe4360, argc=0, argv=0x0) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./ovms_command.cpp:257
#30 0x40127209 in OvmsCommand::Execute (this=0x3ffce740, verbosity=65535, writer=0x3ffe4360, argc=1, argv=0x3ffe6c98) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./ovms_command.cpp:302
#31 0x401271fc in OvmsCommand::Execute (this=0x3ffce670, verbosity=65535, writer=0x3ffe4360, argc=2, argv=0x3ffe6c98) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./ovms_command.cpp:298
#32 0x401271fc in OvmsCommand::Execute (this=0x3ffc4428 <MyCommandApp+4>, verbosity=65535, writer=0x3ffe4360, argc=3, argv=0x3ffe6c94) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./ovms_command.cpp:298
#33 0x40127230 in OvmsCommandApp::Execute (this=0x3ffc4424 <MyCommandApp>, verbosity=65535, writer=0x3ffe4360, argc=3, argv=0x3ffe6c90) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./ovms_command.cpp:507
#34 0x401300d4 in Execute (rl=0x3ffe4368, argc=3, argv=0x3ffe6c90) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./ovms_shell.cpp:47
#35 0x400f1dc9 in new_line_handler (pThis=0x3ffe4368) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/components/microrl/./microrl.c:626
#36 0x400f1e2f in microrl_insert_char (pThis=0x3ffe4368, ch=10) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/components/microrl/./microrl.c:674
#37 0x4013013d in OvmsShell::ProcessChars (this=0x3ffe4360, buf=0x3ffe47be "", len=2) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./ovms_shell.cpp:69
#38 0x40125125 in ConsoleAsync::HandleDeviceEvent (this=0x3ffe4360, pEvent=<optimized out>) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./console_async.cpp:158
#39 0x401290ad in OvmsConsole::Service (this=0x3ffe4360) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./ovms_console.cpp:142
#40 0x401291b3 in non-virtual thunk to OvmsConsole::Service() ()
#41 0x40130bbf in TaskBase::Task (object=0x3ffe4490) at /Users/casner/src/github/ovms/vehicle/OVMS.V3/main/./task_base.cpp:131


More information about the OvmsDev mailing list