Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;协同路由泄漏内存和帧 我用CPPCORO在C++中进行协同程序实验。但地址消毒剂似乎总是不高兴,我泄漏内存。为什么?我从未使用原始的new/delete分配过任何内容,也从未使用shared\u ptr造成循环依赖 #包括 #包括 #包括 甲级{ 公众: A(){std::cerr cppcoro::task{ co_等待getACoro(); co_返回; }; 自动coro=[&foo]()->cppcoro::task{ cou_wait foo(); }; cppcoro::sync_wait(coro()); }_C++_Memory Leaks_Coroutine_C++20_C++ Coroutine - Fatal编程技术网

C++;协同路由泄漏内存和帧 我用CPPCORO在C++中进行协同程序实验。但地址消毒剂似乎总是不高兴,我泄漏内存。为什么?我从未使用原始的new/delete分配过任何内容,也从未使用shared\u ptr造成循环依赖 #包括 #包括 #包括 甲级{ 公众: A(){std::cerr cppcoro::task{ co_等待getACoro(); co_返回; }; 自动coro=[&foo]()->cppcoro::task{ cou_wait foo(); }; cppcoro::sync_wait(coro()); }

C++;协同路由泄漏内存和帧 我用CPPCORO在C++中进行协同程序实验。但地址消毒剂似乎总是不高兴,我泄漏内存。为什么?我从未使用原始的new/delete分配过任何内容,也从未使用shared\u ptr造成循环依赖 #包括 #包括 #包括 甲级{ 公众: A(){std::cerr cppcoro::task{ co_等待getACoro(); co_返回; }; 自动coro=[&foo]()->cppcoro::task{ cou_wait foo(); }; cppcoro::sync_wait(coro()); },c++,memory-leaks,coroutine,c++20,c++-coroutine,C++,Memory Leaks,Coroutine,C++20,C++ Coroutine,编译时使用:g++-std=c++20-focorutines main.cpp-o main-lcppcoro-g-o-fsanize=address 然后通过以下方式解决消毒剂投诉: ================================================================= ==274677==ERROR: LeakSanitizer: detected memory leaks Indirect leak of 88 byte(s) in 1 ob

编译时使用:
g++-std=c++20-focorutines main.cpp-o main-lcppcoro-g-o-fsanize=address

然后通过以下方式解决消毒剂投诉:

=================================================================
==274677==ERROR: LeakSanitizer: detected memory leaks

Indirect leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x7ff558d7af41 in operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/asan/asan_new_delete.cpp:99
    #1 0x560128e69267 in operator() /home/marty/Documents/experiments/cpp/main.cpp:47
    #2 0x560128e69267 in main::{lambda()#3}::operator()() const [clone .actor] /home/marty/Documents/experiments/cpp/main.cpp:50

Indirect leak of 80 byte(s) in 1 object(s) allocated from:
    #0 0x7ff558d7af41 in operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/asan/asan_new_delete.cpp:99
    #1 0x560128e6878e in operator() /home/marty/Documents/experiments/cpp/main.cpp:43
    #2 0x560128e6878e in main::{lambda()#2}::operator()() const [clone .actor] /home/marty/Documents/experiments/cpp/main.cpp:45
    #3 0x560128f7b997  (/home/marty/Documents/experiments/cpp/main+0x145997)

Indirect leak of 24 byte(s) in 1 object(s) allocated from:
    #0 0x7ff558d7af41 in operator new(unsigned long) /build/gcc/src/gcc/libsanitizer/asan/asan_new_delete.cpp:99
    #1 0x560128e71168 in __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<A, std::allocator<A>, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) /usr/include/c++/10.2.0/ext/new_allocator.h:115
    #2 0x560128e71168 in std::allocator<std::_Sp_counted_ptr_inplace<A, std::allocator<A>, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long) /usr/include/c++/10.2.0/bits/allocator.h:173
    #3 0x560128e71168 in std::allocator_traits<std::allocator<std::_Sp_counted_ptr_inplace<A, std::allocator<A>, (__gnu_cxx::_Lock_policy)2> > >::allocate(std::allocator<std::_Sp_counted_ptr_inplace<A, std::allocator<A>, (__gnu_cxx::_Lock_policy)2> >&, unsigned long) /usr/include/c++/10.2.0/bits/alloc_traits.h:460
    #4 0x560128e71168 in std::__allocated_ptr<std::allocator<std::_Sp_counted_ptr_inplace<A, std::allocator<A>, (__gnu_cxx::_Lock_policy)2> > > std::__allocate_guarded<std::allocator<std::_Sp_counted_ptr_inplace<A, std::allocator<A>, (__gnu_cxx::_Lock_policy)2> > >(std::allocator<std::_Sp_counted_ptr_inplace<A, std::allocator<A>, (__gnu_cxx::_Lock_policy)2> >&) /usr/include/c++/10.2.0/bits/allocated_ptr.h:97
    #5 0xbe0b47d5ffffffff  (<unknown module>)

SUMMARY: AddressSanitizer: 192 byte(s) leaked in 3 allocation(s).
=================================================================
==274677==错误:泄漏消毒剂:检测到内存泄漏
从以下位置分配的1个对象中存在88字节的间接泄漏:
#0 0x7ff558d7af41在运算符new(未签名长)/build/gcc/src/gcc/libsanitizer/asan/asan_new_delete中。cpp:99
#运算符()中的1 0x560128e69267/home/marty/Documents/experiments/cpp/main.cpp:47
#main中的2 0x560128e69267:{lambda()#3}::operator()()const[clone.actor]/home/marty/Documents/experiments/cpp/main.cpp:50
从以下位置分配的1个对象间接泄漏80字节:
#0 0x7ff558d7af41在运算符new(未签名长)/build/gcc/src/gcc/libsanitizer/asan/asan_new_delete中。cpp:99
#运算符()中的1 0x560128e6878e/home/marty/Documents/experiments/cpp/main.cpp:43
#main中的2 0x560128e6878e:{lambda()#2}::operator()()const[clone.actor]/home/marty/Documents/experiments/cpp/main.cpp:45
#3 0x560128f7b997(/home/marty/Documents/experiments/cpp/main+0x145997)
从以下位置分配的1个对象中有24个字节的间接泄漏:
#0 0x7ff558d7af41在运算符new(未签名长)/build/gcc/src/gcc/libsanitizer/asan/asan_new_delete中。cpp:99
#1 0x560128e71168 in_uugnu_cxx::new_分配器::allocate(无符号长,void const*)/usr/include/c++/10.2.0/ext/new_分配器。h:115
#std::allocator::allocate(无符号长)/usr/include/c++/10.2.0/bits/allocator中的2 0x560128e71168。h:173
#std::allocator_traits::allocate(std::allocator&,无符号长)/usr/include/c++/10.2.0/bits/alloc_traits中的3 0x560128e71168。h:460
#标准中的4 0x560128e71168::uu分配的\u ptr标准::uu分配的\u保护的(标准::分配器&)/usr/include/c++/10.2.0/bits/allocated\u ptr.h:97
#5 0xBE0B47D5FFFFFF()
摘要:AddressSanitizer:192字节在3次分配中泄漏。
据我所知,
shared\u ptr
应该在
co\u wait getACoro();
之后立即销毁。为什么它被认为是泄漏的?为什么协程帧泄漏

编译器:GCC10.2
OS:Linux

我也在我的协同程序库中使用TSAN。这是有史以来最不准确的东西。代码看起来很好,在我看来也不会泄漏。作为一句忠告,在使用协同程序时不要使用lambda捕获。这会造成灾难。lambdas+协同程序不会混合使用。@DavidHaim我同意TSAN是有史以来最准确的东西。但我使用的是ASan来检测泄漏。我后来确认
valgrind
说也有泄漏。除了两个工具都有可能出现故障之外。还有其他方法来确认我是否泄漏?或者确认这是一个实际的编译器/libstdc++错误?如果是这种情况,我会在cppcoro中排除一些泄漏,而不是在您的代码中。您的代码很好。打开一个bcppcoro中的ug。