C 不同的自由订单的双重误差
c++ double free error of different free order
我在测试C 时遇到了一个问题。当我运行第一个代码时,当第二个代码抛出"双免费错误"时,它会抛出。有人知道发生了什么事吗?
Test* test1 = new Test(1);
Test* test2 = new Test(2);
delete test1;
delete test2;
delete test1;
delete test2;
Test* test1 = new Test(1);
Test* test2 = new Test(2);
delete test1;
delete test1;
delete test2;
delete test2;
,要更好地了解程序的堆用法,您可以在gnu/linux上使用valgrind。当我在Valgrind下运行您的程序时,我会得到。请参阅摘要行
总用法:2个Allocs,4 Frees,8个字节分配
valgrind ./a.out
==7594== Memcheck, a memory error detector
==7594== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==7594== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==7594== Command: ./a.out
==7594==
==7594== Invalid free() / delete / delete[] / realloc()
==7594== at 0x4C2A360: operator delete(void*) (vg_replace_malloc.c:507)
==7594== by 0x40069E: main (in /home/ppm/algo/src/stackoverflow/a.out)
==7594== Address 0x5a02040 is 0 bytes inside a block of size 4 free'd
==7594== at 0x4C2A360: operator delete(void*) (vg_replace_malloc.c:507)
==7594== by 0x400686: main (in /home/ppm/algo/src/stackoverflow/a.out)
==7594==
==7594== Invalid free() / delete / delete[] / realloc()
==7594== at 0x4C2A360: operator delete(void*) (vg_replace_malloc.c:507)
==7594== by 0x4006AA: main (in /home/ppm/algo/src/stackoverflow/a.out)
==7594== Address 0x5a02090 is 0 bytes inside a block of size 4 free'd
==7594== at 0x4C2A360: operator delete(void*) (vg_replace_malloc.c:507)
==7594== by 0x400692: main (in /home/ppm/algo/src/stackoverflow/a.out)
==7594==
==7594==
==7594== HEAP SUMMARY:
==7594== in use at exit: 0 bytes in 0 blocks
==7594== total heap usage: 2 allocs, 4 frees, 8 bytes allocated
==7594==
==7594== All heap blocks were freed -- no leaks are possible
==7594==
==7594== For counts of detected and suppressed errors, rerun with: -v
==7594== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
相关文章:
- 为什么在浮点中从大到小会引入更多的误差
- 如何针对特定情况调试和修复此双自由内存损坏问题
- 将自由函数绑定为类成员函数
- 静态数组的自由动态数组
- 调试和自由执行中的信号处理
- 如何将成员函数作为回调参数传递给需要"typedef-ed"自由函数指针的函数?
- 为什么成员函数地址离自由函数这么远?
- 如何理解C++中链表的自由列表实现?
- 检测到堆栈粉碎,中止,OpenGl 自由过剩
- 创建 OpenCV 非自由版本 v4.3 时出错,可折叠.cpp错误 C2039、2605
- 如何使用模板元编程在自由函数C++链接两个不相关的类
- 基于相邻元素 c++ 的分段误差范围的循环
- C++ 20 中的运算符 == 和 <=> 应该作为成员还是自由函数实现?
- 瓦尔格林德错误 - 地址0x0不是堆叠的 malloc'd 或自由的
- QImage::p ixel 和 QImage::setPixel 坐标超出范围误差
- 将误差线添加到 VTK 二维散点图
- 动态矩阵特征分解过程中的误差
- 如何在共享库中保留静态库中的自由函数
- 转换为非标量误差是什么意思?我该如何解决?
- C 不同的自由订单的双重误差