mardi 31 mars 2015

Visual C++ 2013 std::string memory leak

During development of proprietary app. I have noticed memory leak, related to std::string in a MS Visual C++ 2013, Update 4.


Take a look at the following (basic) code prototype which causes memory leak:



static std::string MemoryLeakTest()
{
static size_t const test_size = 2002;
std::unique_ptr<char[]> result1(new char[test_size]);
std::string result2(result1.get(), test_size);
return result2;
}


calling it by:



std::string const testML = MemoryLeakTest();
std::cout << testML << std::endl;


Am I doing something wrong, or is it a memory leak in a Visual C++ STL?


Aucun commentaire:

Enregistrer un commentaire