Opened 5 years ago

#13305 new Bugs

memory leaks

Reported by: vgtinenko@… Owned by: Andrey Semashev
Milestone: To Be Determined Component: log
Version: Boost 1.65.0 Severity: Problem
Keywords: Cc:

Description

I create a logger in the main thread. If the logger is called from another std::thread there are no problems, but if it's called from the concurrency::create_task - there are lot of memory leaks. Visual Studio 2015, Boost versions: 1.57 and 1.65.1. For example:

Dumping objects ->
{887} normal block at 0x00B6A0F8, 128 bytes long.
 Data: < TimeStamp: 2017> 00 54 69 6D 65 53 74 61 6D 70 3A 20 32 30 31 37 

Best regards, Victor.

The sample code:

// ConsoleApplication_wo_MFC.cpp : Defines the entry point for the console application.
//

#define _CRT_SECURE_NO_WARNINGS
#define BOOST_SYSTEM_NO_DEPRECATED
#define BOOST_LIB_DIAGNOSTIC
#define CGAL_LIB_DIAGNOSTIC

#include <stdio.h>
#include <tchar.h>
#include <windows.h>
#include <ppltasks.h>
#include <thread>

#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/attributes.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/support/date_time.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost\log\sinks\text_file_backend.hpp>
#include <boost/locale/localization_backend.hpp>

#if !defined(BOOST_LOG_NO_THREADS)
#include <boost/thread/locks.hpp>
#include <boost/thread/mutex.hpp>
#endif // !defined(BOOST_LOG_NO_THREADS)

using namespace std;
namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;
namespace expr = boost::log::expressions;

BOOST_LOG_ATTRIBUTE_KEYWORD(a_channel, "Channel", std::string)

int main()
{
	int nRetCode = 0;
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

	typedef sinks::synchronous_sink<sinks::text_file_backend> file_sink;

	src::severity_channel_logger_mt<boost::log::trivial::severity_level> logger(keywords::channel = "L");
	boost::shared_ptr<file_sink> sinkT(new file_sink(keywords::file_name = "logs\\TestLogger_%6N.log"));
	sinkT->set_formatter
	(
		expr::stream
		<< " TimeStamp: " << expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S")
		<< " ThreadID: " << expr::attr<logging::thread_id>("ThreadID")
		<< " Message: " << expr::smessage
	);
	logging::core::get()->add_sink(sinkT);
	sinkT->set_filter(a_channel == "L");
	logging::add_common_attributes();

	BOOST_LOG(logger) << L"A message from the MAIN thread";

	std::thread testTthread([&]()
	{
		BOOST_LOG(logger) << L"A message from the std::thread";
	});
	testTthread.join();

	auto task = concurrency::create_task([&]()
	{
		// Produces memory leaks
		BOOST_LOG(logger) << L"A message from the concurrency::create_task thread";
	});

	task.wait();
	BOOST_LOG(logger) << L"Is concurrency::create_task done: " << task.is_done();
	return nRetCode;
}

Change History (0)

Note: See TracTickets for help on using tickets.