0

The server application always crashes at the same line in code. I used gdb and valgrind to find the problem, but it seems the crash point is in a compiler created destructor, and this is what valgrind says:

==27785== Invalid read of size 8
==27785==    at 0x5CDCE25: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib64/libstdc++.so.6.0.8)
==27785==    by 0x5812F4: Pet::BookConfiguration::~BookConfiguration() (BookConfiguration.h:8)
==27785==    by 0x5EDEC4: void std::_Destroy<Pet::BookConfiguration>(Pet::BookConfiguration*) (stl_construct.h:107)
==27785==    by 0x5EDEE2: void std::__destroy_aux<Pet::BookConfiguration*>(Pet::BookConfiguration*, Pet::BookConfiguration*, __false_type) (stl_construct.h:12
2)
==27785==    by 0x5EDF17: void std::_Destroy<Pet::BookConfiguration*>(Pet::BookConfiguration*, Pet::BookConfiguration*) (stl_construct.h:155)
==27785==    by 0x5EDF3A: void std::_Destroy<Pet::BookConfiguration*, Pet::BookConfiguration>(Pet::BookConfiguration*, Pet::BookConfiguration*, std::allocator
<Pet::BookConfiguration>) (stl_construct.h:182)
==27785==    by 0x5F5C09: std::vector<Pet::BookConfiguration, std::allocator<Pet::BookConfiguration> >::~vector() (stl_vector.h:272)
==27785==    by 0x5F6A22: Pet::ShopModel::~ShopModel() (ShopModel.h:15)
==27785==    by 0x5C59E3: Pet::PetProcessor::climbFight(Pet::SourceList&, Pet::TBuffer&) (PetProcessor.cpp:1796)
==27785==    by 0x589263: Pet::Processor::execute(Pet::SourceList&, unsigned short, Pet::TBuffer&) (Processor.cpp:22)
==27785==    by 0x578627: Pet::JobThread<Pet::PetProcessor>::run() (JobThread.h:66)
==27785==    by 0x4F81AB2: Poco::PooledThread::run() (in /data/home/app100619699/pet_srv/lib/libPocoFoundation.so.11)
==27785==  Address 0x900df30 is 7 bytes after a block of size 57 free'd
==27785==    at 0x4A201B6: operator delete(void*) (vg_replace_malloc.c:457)
==27785==    by 0x5CDCE59: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (in /usr/lib64/libstdc++.so.6.0.8)
==27785==    by 0x5CFFE6: Pet::PetProcessor::getUserBag(Pet::SourceList&, Pet::TBuffer&) (PetProcessor.cpp:446)
==27785==    by 0x589263: Pet::Processor::execute(Pet::SourceList&, unsigned short, Pet::TBuffer&) (Processor.cpp:22)
==27785==    by 0x578627: Pet::JobThread<Pet::PetProcessor>::run() (JobThread.h:66)
==27785==    by 0x4F81AB2: Poco::PooledThread::run() (in /data/home/app100619699/pet_srv/lib/libPocoFoundation.so.11)
==27785==    by 0x4F7D1D5: Poco::ThreadImpl::runnableEntry(void*) (in /data/home/app100619699/pet_srv/lib/libPocoFoundation.so.11)
==27785==    by 0x54DE192: start_thread (in /lib64/libpthread-2.4.so)
==27785==    by 0x6161F0C: clone (in /lib64/libc-2.4.so)

The two string mentioned here have no relationship, and they are all local variables. Who can tell me why it happens or how can I find the real crash problem?

Pet::BookConfiguration::~BookConfiguration() is a compiler created destructor. It need not do anything because this class have no resource to release.

4

1 回答 1

1

从错误消息中,您显然正在使用线程以及线程之间的某种类型的共享存储池。当您关闭服务器时,您可能会遇到两个不同的线程试图破坏共享资源的问题,并且无论哪个线程第二个都会创建崩溃条件,因为两次破坏共享对象是未定义的行为。

请记住,两个单独的线程实际上不需要使用相同的共享对象,但是如果一个线程销毁另一个线程正在使用其中的对象的池,那么第二个线程无法销毁池中的该对象,因为第一个线程已经破坏了该资源。因此,您可能会遇到排序问题、线程资源之间的所有权问题,或者两者兼而有之。

于 2012-09-20T02:38:27.013 回答