C++ 损坏的双链表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17899508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 21:32:00  来源:igfitidea点击:

corrupted double-linked list?

c++operating-system

提问by Amit Bhaira

I am just debugging a big project and and getting this error

我只是在调试一个大项目并收到此错误

*** glibc detected *** p_appmanager/obj/appmanager: corrupted double-linked list: 0x08325e18 **

I have tried to debug the code with the valgrind, but I am not much familiar with this tool. So I am dumping the logs here if you can find out anything from them please let me know.

我试过用valgrind调试代码,但我对这个工具不太熟悉。所以我将日志转储在这里,如果你能从它们中找到任何信息,请告诉我。

Can anyone explain what the following error message could mean?

任何人都可以解释以下错误消息可能意味着什么?

==2181== Invalid read of size 1
==2181==    at 0x402C658: strlen (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x40FCC2D: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181==  Address 0x4359234 is 12 bytes inside a block of size 21 free'd
==2181==    at 0x402ACFC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x410899A: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4071B37: void std::_Destroy_aux<false>::__destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x40717DC: void std::_Destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x4071041: void std::_Destroy<std::string*, std::string>(std::string*, std::string*, std::allocator<std::string>&) (in /usr/lib/libparser.so)
==2181==    by 0x407088A: std::vector<std::string, std::allocator<std::string> >::~vector() (in /usr/lib/libparser.so)
==2181==    by 0x406F497: Parser::parse(std::string) (in /usr/lib/libparser.so)
==2181==    by 0x40729E2: getMessage(int, Message**) (in /usr/lib/libparser.so)
==2181==    by 0x804CB99: fifoThread(void*) (in /home/cleanhands/SBISSW (2)/p_appmanager/obj/appmanager)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181== 
==2181== Invalid read of size 1
==2181==    at 0x402C663: strlen (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x40FCC2D: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181==  Address 0x4359235 is 13 bytes inside a block of size 21 free'd
==2181==    at 0x402ACFC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x410899A: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4071B37: void std::_Destroy_aux<false>::__destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x40717DC: void std::_Destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x4071041: void std::_Destroy<std::string*, std::string>(std::string*, std::string*, std::allocator<std::string>&) (in /usr/lib/libparser.so)
==2181==    by 0x407088A: std::vector<std::string, std::allocator<std::string> >::~vector() (in /usr/lib/libparser.so)
==2181==    by 0x406F497: Parser::parse(std::string) (in /usr/lib/libparser.so)
==2181==    by 0x40729E2: getMessage(int, Message**) (in /usr/lib/libparser.so)
==2181==    by 0x804CB99: fifoThread(void*) (in /home/cleanhands/SBISSW (2)/p_appmanager/obj/appmanager)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181== 
==2181== Invalid read of size 4
==2181==    at 0x402DA08: memcpy (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x4106850: std::basic_streambuf<char, std::char_traits<char> >::xsputn(char const*, int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x40D8CDF: std::basic_filebuf<char, std::char_traits<char> >::xsputn(char const*, int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x40FC9AA: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x40FCC3D: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181==  Address 0x4359234 is 12 bytes inside a block of size 21 free'd
==2181==    at 0x402ACFC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x410899A: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4071B37: void std::_Destroy_aux<false>::__destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x40717DC: void std::_Destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x4071041: void std::_Destroy<std::string*, std::string>(std::string*, std::string*, std::allocator<std::string>&) (in /usr/lib/libparser.so)
==2181==    by 0x407088A: std::vector<std::string, std::allocator<std::string> >::~vector() (in /usr/lib/libparser.so)
==2181==    by 0x406F497: Parser::parse(std::string) (in /usr/lib/libparser.so)
==2181==    by 0x40729E2: getMessage(int, Message**) (in /usr/lib/libparser.so)
==2181==    by 0x804CB99: fifoThread(void*) (in /home/cleanhands/SBISSW (2)/p_appmanager/obj/appmanager)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181== 
==2181== Invalid read of size 2
==2181==    at 0x402DA60: memcpy (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x4106850: std::basic_streambuf<char, std::char_traits<char> >::xsputn(char const*, int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x40D8CDF: std::basic_filebuf<char, std::char_traits<char> >::xsputn(char const*, int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x40FC9AA: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x40FCC3D: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181==  Address 0x4359238 is 16 bytes inside a block of size 21 free'd
==2181==    at 0x402ACFC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x410899A: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4071B37: void std::_Destroy_aux<false>::__destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x40717DC: void std::_Destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x4071041: void std::_Destroy<std::string*, std::string>(std::string*, std::string*, std::allocator<std::string>&) (in /usr/lib/libparser.so)
==2181==    by 0x407088A: std::vector<std::string, std::allocator<std::string> >::~vector() (in /usr/lib/libparser.so)
==2181==    by 0x406F497: Parser::parse(std::string) (in /usr/lib/libparser.so)
==2181==    by 0x40729E2: getMessage(int, Message**) (in /usr/lib/libparser.so)
==2181==    by 0x804CB99: fifoThread(void*) (in /home/cleanhands/SBISSW (2)/p_appmanager/obj/appmanager)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181== 
==2181== Invalid read of size 1
==2181==    at 0x402DA90: memcpy (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x4106850: std::basic_streambuf<char, std::char_traits<char> >::xsputn(char const*, int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x40D8CDF: std::basic_filebuf<char, std::char_traits<char> >::xsputn(char const*, int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x40FC9AA: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x40FCC3D: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181==  Address 0x435923a is 18 bytes inside a block of size 21 free'd
==2181==    at 0x402ACFC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x410899A: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4071B37: void std::_Destroy_aux<false>::__destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x40717DC: void std::_Destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x4071041: void std::_Destroy<std::string*, std::string>(std::string*, std::string*, std::allocator<std::string>&) (in /usr/lib/libparser.so)
==2181==    by 0x407088A: std::vector<std::string, std::allocator<std::string> >::~vector() (in /usr/lib/libparser.so)
==2181==    by 0x406F497: Parser::parse(std::string) (in /usr/lib/libparser.so)
==2181==    by 0x40729E2: getMessage(int, Message**) (in /usr/lib/libparser.so)
==2181==    by 0x804CB99: fifoThread(void*) (in /home/cleanhands/SBISSW (2)/p_appmanager/obj/appmanager)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181== 
==2181== Invalid read of size 1
==2181==    at 0x402DA9C: memcpy (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x4106850: std::basic_streambuf<char, std::char_traits<char> >::xsputn(char const*, int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x40D8CDF: std::basic_filebuf<char, std::char_traits<char> >::xsputn(char const*, int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x40FC9AA: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x40FCC3D: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181==  Address 0x43f0936 is 14 bytes inside a block of size 21 free'd
==2181==    at 0x402ACFC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x410899A: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4071B37: void std::_Destroy_aux<false>::__destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x40717DC: void std::_Destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x4071041: void std::_Destroy<std::string*, std::string>(std::string*, std::string*, std::allocator<std::string>&) (in /usr/lib/libparser.so)
==2181==    by 0x407088A: std::vector<std::string, std::allocator<std::string> >::~vector() (in /usr/lib/libparser.so)
==2181==    by 0x406F497: Parser::parse(std::string) (in /usr/lib/libparser.so)
==2181==    by 0x40729E2: getMessage(int, Message**) (in /usr/lib/libparser.so)
==2181==    by 0x804CB99: fifoThread(void*) (in /home/cleanhands/SBISSW (2)/p_appmanager/obj/appmanager)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181== 
stop tablet
==2181== Invalid read of size 1
==2181==    at 0x402C658: strlen (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x4108EF1: std::string::operator=(char const*) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181==  Address 0x45b2e14 is 12 bytes inside a block of size 21 free'd
==2181==    at 0x402ACFC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x410899A: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4071B37: void std::_Destroy_aux<false>::__destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x40717DC: void std::_Destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x4071041: void std::_Destroy<std::string*, std::string>(std::string*, std::string*, std::allocator<std::string>&) (in /usr/lib/libparser.so)
==2181==    by 0x407088A: std::vector<std::string, std::allocator<std::string> >::~vector() (in /usr/lib/libparser.so)
==2181==    by 0x406F497: Parser::parse(std::string) (in /usr/lib/libparser.so)
==2181==    by 0x40729E2: getMessage(int, Message**) (in /usr/lib/libparser.so)
==2181==    by 0x804CB99: fifoThread(void*) (in /home/cleanhands/SBISSW (2)/p_appmanager/obj/appmanager)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181== 
==2181== Invalid read of size 1
==2181==    at 0x402C663: strlen (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x4108EF1: std::string::operator=(char const*) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181==  Address 0x45b2e15 is 13 bytes inside a block of size 21 free'd
==2181==    at 0x402ACFC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x410899A: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4071B37: void std::_Destroy_aux<false>::__destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x40717DC: void std::_Destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x4071041: void std::_Destroy<std::string*, std::string>(std::string*, std::string*, std::allocator<std::string>&) (in /usr/lib/libparser.so)
==2181==    by 0x407088A: std::vector<std::string, std::allocator<std::string> >::~vector() (in /usr/lib/libparser.so)
==2181==    by 0x406F497: Parser::parse(std::string) (in /usr/lib/libparser.so)
==2181==    by 0x40729E2: getMessage(int, Message**) (in /usr/lib/libparser.so)
==2181==    by 0x804CB99: fifoThread(void*) (in /home/cleanhands/SBISSW (2)/p_appmanager/obj/appmanager)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181== 
==2181== Invalid read of size 1
==2181==    at 0x402DAEA: memcpy (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x4108C7A: std::string::_M_replace_safe(unsigned int, unsigned int, char const*, unsigned int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4108CF8: std::string::assign(char const*, unsigned int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4108F05: std::string::operator=(char const*) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181==  Address 0x45b2e19 is 17 bytes inside a block of size 21 free'd
==2181==    at 0x402ACFC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x410899A: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4071B37: void std::_Destroy_aux<false>::__destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x40717DC: void std::_Destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x4071041: void std::_Destroy<std::string*, std::string>(std::string*, std::string*, std::allocator<std::string>&) (in /usr/lib/libparser.so)
==2181==    by 0x407088A: std::vector<std::string, std::allocator<std::string> >::~vector() (in /usr/lib/libparser.so)
==2181==    by 0x406F497: Parser::parse(std::string) (in /usr/lib/libparser.so)
==2181==    by 0x40729E2: getMessage(int, Message**) (in /usr/lib/libparser.so)
==2181==    by 0x804CB99: fifoThread(void*) (in /home/cleanhands/SBISSW (2)/p_appmanager/obj/appmanager)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181== 
==2181== Invalid read of size 4
==2181==    at 0x402DB18: memcpy (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x4108C7A: std::string::_M_replace_safe(unsigned int, unsigned int, char const*, unsigned int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4108CF8: std::string::assign(char const*, unsigned int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4108F05: std::string::operator=(char const*) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181==  Address 0x45b2e14 is 12 bytes inside a block of size 21 free'd
==2181==    at 0x402ACFC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x410899A: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4071B37: void std::_Destroy_aux<false>::__destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x40717DC: void std::_Destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x4071041: void std::_Destroy<std::string*, std::string>(std::string*, std::string*, std::allocator<std::string>&) (in /usr/lib/libparser.so)
==2181==    by 0x407088A: std::vector<std::string, std::allocator<std::string> >::~vector() (in /usr/lib/libparser.so)
==2181==    by 0x406F497: Parser::parse(std::string) (in /usr/lib/libparser.so)
==2181==    by 0x40729E2: getMessage(int, Message**) (in /usr/lib/libparser.so)
==2181==    by 0x804CB99: fifoThread(void*) (in /home/cleanhands/SBISSW (2)/p_appmanager/obj/appmanager)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181== 
Success:: tablet process terminated Successfully.
CONSOLE>start tablet
Success:: tablet Process Created Successfully
CONSOLE>stop tablet
==2181== Invalid read of size 4
==2181==    at 0x402DA08: memcpy (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x4108C7A: std::string::_M_replace_safe(unsigned int, unsigned int, char const*, unsigned int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4108CF8: std::string::assign(char const*, unsigned int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4108F05: std::string::operator=(char const*) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181==  Address 0x45dd8c4 is 12 bytes inside a block of size 21 free'd
==2181==    at 0x402ACFC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x410899A: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4071B37: void std::_Destroy_aux<false>::__destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x40717DC: void std::_Destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x4071041: void std::_Destroy<std::string*, std::string>(std::string*, std::string*, std::allocator<std::string>&) (in /usr/lib/libparser.so)
==2181==    by 0x407088A: std::vector<std::string, std::allocator<std::string> >::~vector() (in /usr/lib/libparser.so)
==2181==    by 0x406F497: Parser::parse(std::string) (in /usr/lib/libparser.so)
==2181==    by 0x40729E2: getMessage(int, Message**) (in /usr/lib/libparser.so)
==2181==    by 0x804CB99: fifoThread(void*) (in /home/cleanhands/SBISSW (2)/p_appmanager/obj/appmanager)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181== 
==2181== Invalid read of size 2
==2181==    at 0x402DA60: memcpy (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x4108C7A: std::string::_M_replace_safe(unsigned int, unsigned int, char const*, unsigned int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4108CF8: std::string::assign(char const*, unsigned int) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4108F05: std::string::operator=(char const*) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181==  Address 0x45dd8c8 is 16 bytes inside a block of size 21 free'd
==2181==    at 0x402ACFC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2181==    by 0x410899A: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2181==    by 0x4071B37: void std::_Destroy_aux<false>::__destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x40717DC: void std::_Destroy<std::string*>(std::string*, std::string*) (in /usr/lib/libparser.so)
==2181==    by 0x4071041: void std::_Destroy<std::string*, std::string>(std::string*, std::string*, std::allocator<std::string>&) (in /usr/lib/libparser.so)
==2181==    by 0x407088A: std::vector<std::string, std::allocator<std::string> >::~vector() (in /usr/lib/libparser.so)
==2181==    by 0x406F497: Parser::parse(std::string) (in /usr/lib/libparser.so)
==2181==    by 0x40729E2: getMessage(int, Message**) (in /usr/lib/libparser.so)
==2181==    by 0x804CB99: fifoThread(void*) (in /home/cleanhands/SBISSW (2)/p_appmanager/obj/appmanager)
==2181==    by 0x4054D4B: start_thread (pthread_create.c:308)
==2181==    by 0x4269DDD: clone (clone.S:130)
==2181== 

回答by sehe

It looks like a thread is printing data (char*character data) that was already freed on the main (or another) thread.

看起来一个线程正在打印char*已经在主(或另一个)线程上释放的数据(字符数据)。

More specificly, Parser::parsebuilds a vectorof std::strings.

更specificly,Parser::parse建立一个vectorstd::string秒。



EDITAs requested in the comment, this is what I read, with [highlights]:

编辑根据评论中的要求,这就是我阅读的内容,使用[highlights]

==2181==[Invalid read of size 1]
==2181==at 0x402C658: strlen (in /usr/lib/valgrind/vg...
==2181==by 0x40FCC2D: std::basic_ostream<char, std::c...
==2181==by 0x4054D4B: start_thread (pthread_create.c:...
==2181==by 0x4269DDD: clone (clone.S:130)
==2181==[Address 0x4359234]is 12 bytes inside[a block of size 21 free'd]
==2181==at 0x402ACFC: operator delete(void*) (in /usr...
==2181==by 0x410899A: std::string::_Rep::_M_destroy(s...
==2181==by 0x4071B37: void std::_Destroy_aux<false>::...
==2181==by 0x40717DC: void std::_Destroy<std::string*...
==2181==by 0x4071041: void std::_Destroy<std::string*...
==2181== by 0x407088A: std::vector<std::string, std::a...[::~vector()](in /usr/lib/libparser.so
==2181== by 0x406F497:[Parser::parse(std::string)](in /usr/lib/libparser.so
==2181==by 0x40729E2: getMessage(int, Message**) (in ...
==2181==by 0x804CB99: fifoThread(void*) (in /home/cle...
==2181==by 0x4054D4B: start_thread (pthread_create.c:...
==2181==by 0x4269DDD: clone (clone.S:130

==2181==[ Invalid read of size 1] [ ] [ ] [ ] [ ]
==2181==at 0x402C658: strlen (in /usr/lib/valgrind/vg...
==2181==by 0x40FCC2D: std::basic_ostream<char, std::c...
==2181==by 0x4054D4B: start_thread (pthread_create.c:...
==2181==by 0x4269DDD: clone (clone.S:130)
==2181==Address 0x4359234is 12 bytes insidea block of size 21 free'd
==2181==at 0x402ACFC: operator delete(void*) (in /usr...
==2181==by 0x410899A: std::string::_Rep::_M_destroy(s...
==2181==by 0x4071B37: void std::_Destroy_aux<false>::...
==2181==by 0x40717DC: void std::_Destroy<std::string*...
==2181==by 0x4071041: void std::_Destroy<std::string*...
==2181== by 0x407088A: std::vector<std::string, std::a...::~vector()(in /usr/lib/libparser.so
==2181== by 0x406F497:Parser::parse(std::string)(in /usr/lib/libparser.so
==2181==by 0x40729E2: getMessage(int, Message**) (in ...
==2181==by 0x804CB99: fifoThread(void*) (in /home/cle...
==2181==by 0x4054D4B: start_thread (pthread_create.c:...
==2181==by 0x4269DDD: clone (clone.S:130

And I noticed the other backtracecs all highlighted the same pattern.

我注意到其他回溯都突出显示了相同的模式。



Apparently, some thread(s) get started, and they are passed references (in)to these strings. However, since the vector is local to Parser::parse(probably an automatic variable, or explicitely deleted), the references are no longer valid (e.g. at the time the strings are being streamed using std::ostream::operator<<(std::ostream&, const char*)).

显然,一些线程开始了,并且它们被传递(输入)到这些字符串的引用。然而,由于向量是本地的Parser::parse(可能是一个自动变量,或者被显式删除),引用不再有效(例如,在使用 流式传输字符串时std::ostream::operator<<(std::ostream&, const char*))。

Sadly, the stack trace doesn't quite show what name/object module contains the offending line, but you can see it lives on a separate thread (due to the presence of start_thread)

遗憾的是,堆栈跟踪并没有完全显示出包含违规行的名称/对象模块,但您可以看到它存在于单独的线程上(由于存在start_thread

EditApparently, the thread(s) take a referenceto the strings (from the vector) because the thread is alsotrying to assign the strings to another string.

编辑显然,线程引用strings(来自向量),因为线程试图将字符串分配给另一个string.

This might indicate that the programmer was aware of the fact that the refence was not reliable and tries to copy it to a thread-local variable. Maybe it's just that there's a race condition involved and the strings don't even live long enough for the local copy to work.

这可能表明程序员意识到引用不可靠并试图将其复制到线程局部变量的事实。也许这只是因为存在竞争条件,并且strings 甚至没有足够长的时间让本地副本正常工作。

IOW. It would appear that a thread is being started as such:

哎哟。似乎正在启动一个线程:

#include <future>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <iostream>

using namespace std;

// sample: return the largest integer value or 42
int some_background_worker(vector<string> const& ref_data)
{
    if (ref_data.empty()) return 42;

    vector<int> values(ref_data.size());
    transform(begin(ref_data), end(ref_data), begin(values), 
            [](string const& s) { return stoi(s); });
    return *max_element(begin(values), end(values));
}

struct Parser
{
    future<int> parse(string const& msg) const
    {
        istringstream iss(msg);
        istream_iterator<string> f(iss), l;

        const vector<string> data { f, l };

        // now dispatch a thread to do the work
        return async(some_background_worker, ref(data));
    }
};

int main() // mimicks your "fifoThread" function
{
    // we use a simple vector to stub your fifo queue:
    const std::vector<string> fifoQueue { "1 3 9 -1 2", "32389 3102 -34 -888", "-42 -889", "" };

    vector<future<int>> results;

    {
        Parser parser;
        for(auto& msg : fifoQueue)
            results.push_back(parser.parse(msg));
    }

    // all parser data has been throroughly destroyed, before we might even
    // start the workers
    for(auto& fut: results)
        std::cout << "result of worker: " << fut.get() << "\n";
}

Here, the same race condition occurs, as a reference to "soon-to-be-stale" data is passed to the thread:

在这里,发生了相同的竞争条件,因为对“soon-to-be-stale”数据的引用被传递给线程:

async(some_background_worker, ref(data));

It crashes with bad_allocon my system (which is bogus, but perfectly fine Undefined Behaviour).

bad_alloc在我的系统上崩溃(这是虚假的,但完美的未定义行为)。

Like I said above, the std::string::assigncalls might indicate the thread attempts to copy the data locally, like:

就像我上面说的那样,std::string::assign调用可能表明线程尝试在本地复制数据,例如:

vector<string> local_copy(ref_data);

But that will stillbe a data race, because (without explicit synchronization) there is no guarantee that ref_datais valid even at that point.

但这仍然数据竞争,因为(没有显式同步)ref_data即使在那时也不能保证有效。



Fix it by movingthe data into the thread instead:

通过数据移动到线程中来修复它:

int some_background_worker(vector<string> data);

// and then, in parse(...):
    async(some_background_worker, std::move(data));

Now, on my system, it runs and prints

现在,在我的系统上,它运行并打印

result of worker: 9
result of worker: 32389
result of worker: -42
result of worker: 42

fully as expected. See it running live at Coliru

完全符合预期。在 Coliru 现场观看它的运行