Windows memory leak async function

In my application, I introduced a memory leak when I started using std :: async. After examining the problem using the Dr. memory, I found that std :: async leaks very often.

I made a quick test that reproduces the problem:

#include <Windows.h>
#include <algorithm>
#include <future>

using namespace std;

void testMethod()
{
    for (int i = 0; i < 4; i++)
        Sleep(10);
}

int main()
{
    for (int i = 0; i < 100; i++)
    {
        auto result = async(launch::async, testMethod);
        result.wait();
    }

    return 1;
}

      

How is it possible that the above code would cause a memory leak on Windows? The problem does not occur on Linux. The following log will appear in the Dr.Web memory:

Error #1: REACHABLE LEAK 40 direct bytes 0x007badb8-0x007bade0 + 0 indirect bytes
# 0 replace_operator_new_nomatch                                   [d:\drmemory_package\common\alloc_replace.c:2732]
# 1 MSVCR120D.dll!Concurrency::details::SubAllocator::Alloc        [f:\dd\vctools\crt\crtw32\concrt\suballocator.cpp:201]
# 2 MSVCR120D.dll!Concurrency::details::ExternalContextBase::Alloc [f:\dd\vctools\crt\crtw32\concrt\externalcontextbase.cpp:238]
# 3 MSVCR120D.dll!Concurrency::Alloc                               [f:\dd\vctools\crt\crtw32\concrt\suballocator.cpp:34]
# 4 Concurrency::details::_AllocBase::operator new                 [c:\program files (x86)\microsoft visual studio 12.0\vc\include\concrt.h:298]
# 5 Concurrency::task<>::_TaskInitWithFunctor<>                    [c:\program files (x86)\microsoft visual studio 12.0\vc\include\ppltasks.h:3982]
# 6 Concurrency::task<>::_TaskInitMaybeFunctor<>                   [c:\program files (x86)\microsoft visual studio 12.0\vc\include\ppltasks.h:4551]
# 7 Concurrency::task<>::task<><>                                  [c:\program files (x86)\microsoft visual studio 12.0\vc\include\ppltasks.h:4198]
# 8 Concurrency::create_task<>                                     [c:\program files (x86)\microsoft visual studio 12.0\vc\include\ppltasks.h:4673]
# 9 std::_Task_async_state<>::_Task_async_state<><>                [c:\program files (x86)\microsoft visual studio 12.0\vc\include\future:906]
#10 std::_Get_associated_state<>                                   [c:\program files (x86)\microsoft visual studio 12.0\vc\include\future:1859]
#11 std::_Async<>      

      

+3
asynchronous memory-leaks c ++ 11 visual-studio-2013 dr-memory


source to share


No one has answered this question yet

Check out similar questions:

3044
Making a memory leak with Java
1783
C ++ 11 introduced a standardized memory model. What does it mean? And how will this affect C ++ programming?
1146
performSelector may leak because its selector is unknown
1042
The result was a leak of the window that was originally added
957
How and when to use "async and await"
226
Is std :: unique_ptr <T> necessary to define the complete definition of T?
7
Why is the source code of the Visual Studio Runtime Library stored in two directories?
2
xtgmath.h has compile time errors
1
Useless errors (<chrono> <random> C ++ Standard Libraries)
0
Can't define std :: function variable from virtual method pointer in vs2013



All Articles
Loading...
X
Show
Funny
Dev
Pics