gpt4 book ai didi

c++ - 返回 vector> 会导致 gcc 编译代码 (curlcpp) 崩溃

转载 作者:行者123 更新时间:2023-11-28 05:16:59 25 4
gpt4 key购买 nike

我在使用 curlcpp 的 gcc 编译代码中遇到奇怪的间歇性崩溃。这是片段-

catch (curl_easy_exception error) {
// If you want to get the entire error stack we can do:
curlcpp_traceback errors = error.get_traceback();

澄清一下,curlcpp_traceback 是 std::vector<std::pair<std::string, std::string>> 的类型定义和 get_traceback按值返回静态 vector 。

崩溃发生在赋值点,似乎是 vector 破坏的结果。这是来自 gdb 的 bt。

#0  0x00007f1d777c8418 in raise () from /root/ibm/shared/PIMGW1/files/lib/x86_64-linux-gnu/libc.so.6
#1 0x00007f1d777ca01a in abort () from /root/ibm/shared/PIMGW1/files/lib/x86_64-linux-gnu/libc.so.6
#2 0x00007f1d7780a72a in ?? () from /root/ibm/shared/PIMGW1/files/lib/x86_64-linux-gnu/libc.so.6
#3 0x00007f1d77816c18 in free () from /root/ibm/shared/PIMGW1/files/lib/x86_64-linux-gnu/libc.so.6
#4 0x0000000000d1aa7b in deallocate (this=0x7f1d6c0c44c0, __p=<optimized out>) at /usr/include/c++/5/ext/new_allocator.h:110
#5 deallocate (__a=..., __n=<optimized out>, __p=<optimized out>) at /usr/include/c++/5/bits/alloc_traits.h:517
#6 _M_destroy (__size=<optimized out>, this=0x7f1d6c0c44c0) at /usr/include/c++/5/bits/basic_string.h:185
#7 _M_dispose (this=0x7f1d6c0c44c0) at /usr/include/c++/5/bits/basic_string.h:180
#8 ~basic_string (this=0x7f1d6c0c44c0, __in_chrg=<optimized out>) at /usr/include/c++/5/bits/basic_string.h:543
#9 ~pair (this=0x7f1d6c0c44c0, __in_chrg=<optimized out>) at /usr/include/c++/5/bits/stl_pair.h:96
#10 _Destroy<std::pair<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> > > (__pointer=<optimized out>) at /usr/include/c++/5/bits/stl_construct.h:93
#11 __destroy<std::pair<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >*> (__last=<optimized out>, __first=0x7f1d6c0c44c0) at /usr/include/c++/5/bits/stl_construct.h:103
#12 _Destroy<std::pair<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >*> (__last=<optimized out>, __first=<optimized out>) at /usr/include/c++/5/bits/stl_construct.h:126
#13 _Destroy<std::pair<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >*, std::pair<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> > > (__last=0x7f1d6c12ffc0, __first=<optimized out>) at /usr/include/c++/5/bits/stl_construct.h:151
#14 std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::~vector (this=0x7f1d71ad6350, __in_chrg=<optimized out>) at /usr/include/c++/5/bits/stl_vector.h:424

bt 中的 #15 是上面显示的分配。

它似乎表明一个载体正在被摧毁。这可能是返回的 vector ,所以它不是不自然的。不清楚的是它崩溃的原因。

如有任何帮助,我们将不胜感激。

最佳答案

就我从源代码(它的 here ,对吗?)来看,复制不受相应互斥体的保护。因此,可能会出现这样一种情况,即 insert 触发内存重新分配,而另一个线程正在复制此 vector ,这会导致内存损坏。

关于c++ - 返回 vector<pair<string,string>> 会导致 gcc 编译代码 (curlcpp) 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42431681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com