AddressSanitizer GCC 4.8的双重免费错误
Double Free error with AddressSanitizer GCC 4.8
考虑以下玩具程序(prog.cpp
):
class A {
public:
vector<int> vec;
A() noexcept {}
A(vector<int> s) : vec(s) {}
};
class B {
private:
vector<atomic<A>> a_table;
public:
B(int capacity) : a_table(capacity) {}
void update(int index) {
A newValue(vector<int>(10,1));
a_table[index].store(newValue);
}
};
int main(int argc, char** argv)
{
B b(5);
b.update(2);
return 0;
}
当正常编译时(g++ prog.cpp -latomic
),工作良好。但是当编译为g++ -fsanitize=address -fno-omit-frame-pointer prog.cpp -latomic
时,执行时会产生双重自由错误。基于上述类似代码行的程序必须在多线程应用程序中使用,在这种情况下,即使是正常的编译也会产生Double Free错误。我读了"三/五规则",这是在双重自由的情况下通常提到的,还有各种其他文件,但都不起作用。
另外,从class A
的默认构造函数中删除noexcept
指定符会产生这个奇怪的错误,这也是我想知道的。
error: function ‘std::atomic<_Tp>::atomic() [with _Tp = A]’ defaulted on its first declaration with an exception-specification that differs from the implicit declaration ‘std::atomic<A>::atomic()’
atomic() noexcept = default;
^
std::atomic
需要一个平凡的可复制类型,而你的A
不是,因为它的vector<int>
类型的成员(例如)不是平凡的可复制构造的。
从5.0版本开始,GCC只检测违反该要求。
旧版本的gcc编译代码并不意味着它是有效的
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 全球免费给出一个错误.调试器不解释
- 使用线程和静音时,双免费或损坏(!prev)错误
- TBB免费图像lambda阵列比较错误
- 使用数组作为参数时,免费出现c++错误
- 范围末尾的C 双免费或损坏错误
- C 双免费或损坏错误
- 最Vexing的朋友?朋友化一个专门的免费函数模板会引发编译错误(当重载一个方法时)
- 使用boost.asio的免费async_*函数时出现奇怪的错误
- AddressSanitizer GCC 4.8的双重免费错误
- 如何处理错误:双重免费或腐败
- 共享所有权双重免费错误
- 双重免费或腐败错误- valgrind