执行析构函数时,服务器应用程序总是崩溃

时间:2012-09-20 02:19:16

标签: c++ valgrind

服务器应用程序始终在代码中的同一行崩溃。我使用gdb和valgrind来查找问题,但似乎崩溃点是在编译器创建的析构函数中,这就是valgrind所说的:

==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)

这里提到的两个字符串没有关系,它们都是局部变量。谁能告诉我它为什么会发生,或者我怎样才能找到真正的崩溃问题?

Pet::BookConfiguration::~BookConfiguration()是编译器创建的析构函数。它不需要做任何事情,因为这个类没有资源可以释放。

1 个答案:

答案 0 :(得分:1)

从错误消息中你明显使用线程以及线程之间的某种类型的共享存储池。您可能遇到一个问题,其中两个不同的线程在您关闭服务器时试图销毁共享资源,而第二个创建崩溃条件的任何线程因为两次销毁共享对象是未定义的行为。

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