我使用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;
}
当我运行它(Windows 7上的Win32 / Debug)时,我在MemoryLeaks.txt中得到以下输出:
Detected memory leaks!
Dumping objects ->
c:\workspace\externals\boost_1_56_0\include\boost\smart_ptr\detail\shared_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:\workspace\externals\boost_1_56_0\include\boost\exception\detail\exception_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:\workspace\externals\boost_1_56_0\include\boost\smart_ptr\detail\shared_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:\workspace\externals\boost_1_56_0\include\boost\exception\detail\exception_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宏进行编译。所以我开始删除所有包含,直到我发现导致报告泄漏的那个是exception_ptr,幸运的是这个用宏编译了。
我为Boost开了一张票(https://svn.boost.org/trac/boost/ticket/10621),但我想我也会在这里试试。我想我也可能做错了。
答案 0 :(得分:0)
就像我在问题中提到的,这是Boost中的一个错误。 您可以在此处看到我打开的门票:https://svn.boost.org/trac/boost/ticket/10621
与此同时,由于我们转移到VC12,我们开始使用std :: thread,所以在我的特殊情况下,它不再是问题了。