应用程序退出时出现SegFault
SegFault on application exit
我在工作中使用的一个应用程序遇到了一个奇怪而烦人的问题。应用程序是用C++编写的,当应用程序终止时(调用主函数return或exit
(,它会因分段错误而崩溃。分段错误似乎是由basic_string类析构函数中的双释放指针引起的。我不能添加源代码,但我可以说这个应用程序非常简单,我没有直接在代码中使用任何指针。该应用程序只是在调用库中的一个函数。
Valgrid发现以下问题:
==5402== Invalid read of size 4
==5402== at 0x549F05F: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (atomicity.h:49)
==5402== by 0x41D1BA4: ??? (in ../Functions.so)
==5402== by 0x436D873: ??? (in ../Functions.so)
==5402== by 0x967674: _dl_fini (in /lib/ld-2.12.so)
==5402== by 0x9A7EAE: exit (in /lib/libc-2.12.so)
==5402== by 0x810F8C2: main (Checker.C:146)
==5402== Address 0x55ec808 is 8 bytes inside a block of size 15 free'd
==5402== at 0x4007895: operator delete(void*) (vg_replace_malloc.c:480)
==5402== by 0x549EF67: std::string::_Rep::_M_destroy(std::allocator<char> const&) (new_allocator.h:110)
==5402== by 0x810F8C2: main (Checker.C:146)
==5402==
==5402== Invalid free() / delete / delete[] / realloc()
==5402== at 0x4007895: operator delete(void*) (vg_replace_malloc.c:480)
==5402== by 0x549EF67: std::string::_Rep::_M_destroy(std::allocator<char> const&) (new_allocator.h:110)
==5402== by 0x41D1BA4: ??? (in ..../Functions.so)
==5402== by 0x436D873: ??? (in .../Functions.so)
==5402== by 0x967674: _dl_fini (in /lib/ld-2.12.so)
==5402== by 0x9A7EAE: exit (in /lib/libc-2.12.so)
==5402== by 0x810F8C2: main (Checker.C:146)
==5402== Address 0x55ec800 is 0 bytes inside a block of size 15 free'd
==5402== at 0x4007895: operator delete(void*) (vg_replace_malloc.c:480)
==5402== by 0x549EF67: std::string::_Rep::_M_destroy(std::allocator<char> const&) (new_allocator.h:110)
==5402== by 0x810F8C2: main (Checker.C:146)
==5402==
该应用程序链接到共享库和静态库。Function.so
是一个共享库,它可能包含一些静态代码。这个问题与链接阶段有关,因为根据库链接到我的可执行文件的顺序,应用程序可能不会崩溃。
我真的很难解决这个问题,你知道这个问题的根本原因是什么吗?有什么建议可以继续调查这个问题吗?
这个问题的根本原因是代码中的某个错误。bug可以是任何东西。野生指针取消引用,从数组末尾运行,或任何数量的其他无数类型的错误。C++代码中的错误并不一定意味着应用程序会立即崩溃。应用程序可以继续执行,但在稍后尝试访问由错误导致的损坏内存时会崩溃。
代码中的某个地方有一个错误,可能会导致内存损坏,当应用程序终止时会触发此崩溃。您需要找到并修复它。欢迎使用C++。
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- C++中带有List类的迭代器Segfault
- 创建LinkedList退出,返回代码为-11(SIGSEGV)
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- 如何让LLDB在成功时退出,在失败时等待
- C++控制台应用程序阻止退出
- 程序在执行程序的其余部分之前退出
- 使用Vulkan hpp vk::enumerateInstanceVersion()会导致segfault
- 构造函数在退出函数时无法初始化一个参数
- 为什么异常不退出程序?
- 我不断收到 [错误] ID 返回 1 退出状态错误,但看不到问题所在
- 退出简单while循环时出现问题
- 使用vscode调试时,GDB意外退出
- SegFault 同时使用 std::string::operator+= 和函数作为参数
- pclose() 不会给我进程退出代码
- 为什么系统函数总是在C++中返回已转移的退出状态?
- C++从另一个函数退出函数
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- C STL映射中的SegFault由于过程退出期间的静态可变清理而找到
- 应用程序退出时出现SegFault