Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#10621 closed Bugs (invalid)

CRT Debug Heap reports leak when including exception_ptr.hpp

Reported by: dinazil@… Owned by: Emil Dotchevski
Milestone: To Be Determined Component: exception
Version: Boost 1.56.0 Severity: Problem
Keywords: Cc:

Description

I created a Win32 Console application with Visual Studio 2013 (vc12) and Boost 1.56.0.

This is my only file:

#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;
}

When I run this I get the following output in 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.

I first discovered this issue in a unit test which included boost/thread.hpp. However the unit tests don't include source and line information about the leak and thread.hpp doesn't compile with the DEBUG_CLIENTBLOCK macro. So I started eliminating all includes until I found out that the one causing the reported leak was exception_ptr and luckily enough this one did compile with the macro.

I'm attaching the solution. It assumes that the Boost library resides in c:\workspace\boost_1_56_0.

Thanks!

Attachments (1)

boost_memory_leak_reporo.7z (2.3 KB ) - added by Dina Goldshtein <dinazil@…> 8 years ago.
The VS2013 solution

Download all attachments as: .zip

Change History (6)

by Dina Goldshtein <dinazil@…>, 8 years ago

Attachment: boost_memory_leak_reporo.7z added

The VS2013 solution

comment:1 by Dina Goldshtein <dinazil@…>, 8 years ago

Version: Boost 1.54.0Boost 1.56.0

comment:2 by viboes, 8 years ago

Component: Noneexception
Owner: set to Emil Dotchevski

comment:3 by nonubik, 7 years ago

I have encountered the same issue with boost 1.58.0.

comment:4 by Emil Dotchevski, 7 years ago

Resolution: invalid
Status: newclosed

comment:5 by nonubik, 7 years ago

That did not solve my specific issue, but I have found out my issue was similar (I can detail on it and its fix if needed) and indeed the memory leaks were reported too early, thus false.

Note: See TracTickets for help on using tickets.