CRT调试堆在包含exception_ptr.hpp时报告泄漏
CRT Debug Heap reports leak when including exception_ptr.hpp
我使用Visual Studio 2013(vc12)和Boost 1.56.0创建了一个Win32控制台应用程序。
这是我唯一的文件:
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
//#define CHECK_THREAD
#ifdef CHECK_THREAD
#include <boost/thread.hpp>
#else
#ifdef _DEBUG
#define DEBUG_CLIENTBLOCK new( _CLIENT_BLOCK, __FILE__, __LINE__)
#else
#define DEBUG_CLIENTBLOCK
#endif // _DEBUG
#ifdef _DEBUG
#define new DEBUG_CLIENTBLOCK
#endif
#include <boost/exception/detail/exception_ptr.hpp>
#endif
#include <Windows.h>
int main()
{
HANDLE hLogFile = CreateFile(L"MemoryLeaks.txt", GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
//Turn on debugging for memory leaks. This is automatically turned off when the build is Release.
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_WARN, hLogFile);
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ERROR, hLogFile);
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
_CrtSetReportFile(_CRT_ASSERT, hLogFile);
_CrtDumpMemoryLeaks();
CloseHandle(hLogFile);
return 0;
}
当我运行这个(Win32/Debug在Windows7上)时,我在MemoryLeaks.txt中得到以下输出:
Detected memory leaks!
Dumping objects ->
c:workspaceexternalsboost_1_56_0includeboostsmart_ptrdetailshared_count.hpp(130) : {156} client block at 0x00709AC8, subtype 0, 16 bytes long.
Data: < 0 p > 84 0F 0C 00 02 00 00 00 01 00 00 00 30 9A 70 00
{155} normal block at 0x00709A88, 14 bytes long.
Data: <bad exception > 62 61 64 20 65 78 63 65 70 74 69 6F 6E 00
c:workspaceexternalsboost_1_56_0includeboostexceptiondetailexception_ptr.hpp(130) : {154} client block at 0x00709A30, subtype 0, 44 bytes long.
Data: < @ > 04 0E 0C 00 00 00 00 00 40 0E 0C 00 F0 0C 0C 00
c:workspaceexternalsboost_1_56_0includeboostsmart_ptrdetailshared_count.hpp(130) : {151} client block at 0x007089B0, subtype 0, 16 bytes long.
Data: <h X p > 68 0F 0C 00 02 00 00 00 01 00 00 00 58 89 70 00
c:workspaceexternalsboost_1_56_0includeboostexceptiondetailexception_ptr.hpp(130) : {150} client block at 0x00708958, subtype 0, 44 bytes long.
Data: < X > B4 0C 0C 00 00 00 00 00 58 0D 0C 00 F0 0C 0C 00
Object dump complete.
我第一次发现这个问题是在一个包含boost/thread.hpp的单元测试中。然而,单元测试不包括有关泄漏的源代码和行信息,thread.hpp也不使用DEBUG_CLIENTBLOCK宏编译。所以我开始消除所有的include,直到我发现导致报告泄漏的是exception_ptr,幸运的是,这个包确实用宏编译了。
我开了一张票给Boost(https://svn.boost.org/trac/boost/ticket/10621)但我想我也可以在这里试试。我想我也有可能做错了什么。
就像我在问题中提到的,这是Boost中的一个bug。你可以在这里看到我打开的票:https://svn.boost.org/trac/boost/ticket/10621
同时,由于我们转移到了VC12,我们开始使用std::thread,所以在我的具体情况下,这不再是一个问题。
相关文章:
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 什么是"#include <boost/functional/hash.hpp> "?
- 使用Vulkan hpp vk::enumerateInstanceVersion()会导致segfault
- CLANG 编译器 说:变量"PTR"可能未初始化
- 在以唯一ptr为值的C++映射中,动态内存何时会被销毁
- 如何将class.cpp和class.hpp编译为一个.o文件
- 将 ptr 传递给 ptr 到 A 作为参数传递给 A 的函数是不好的做法吗?
- g++ -I 和 -L 命令来查找不起作用的 .hpp 文件
- VS Code C++:不准确的系统包括路径错误(wchar.h,boost/lambda/lambda.hpp)
- 为共享 ptr 向量实现复制 c'tor?
- 字符和整数中 **(ptr+1) 的值差异
- C++:在不中断共享的情况下通过引用传递共享 PTR?
- 如何将派生类从基 ptr 分配给 nlohmann::json
- Gnuplot_i.hpp C++接口绘制局部变量而不是文件
- 引用 std::shared:ptr 以避免引用计数
- 致命错误:找不到'boost/uuid/uuid.hpp'文件
- BGL:当包含 random_spanning_tree.hpp 时,对strong_components的调用无法编译
- 造成致命错误:boost/fusion/iterator/equal_to.hpp 没有这样的文件或目录
- 无法使包含.hpp文件与其中的2个文件一起使用
- 为什么我不能在不进行任何转换的情况下将浮点数放入任何类型的 ptr 中?