免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
123下一页
最近访问板块 发新帖
查看: 12227 | 回复: 20
打印 上一主题 下一主题

*** glibc detected *** ./a.out: double free or corruption (out): 0x084602f8 *** [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-05-25 00:14 |只看该作者 |倒序浏览
运行完报错如下,怎么解决?
*** glibc detected *** ./a.out: double free or corruption (out): 0x084602f8 ***
======= Backtrace: =========
/lib/libc.so.6[0x17aac1]
/lib/libc.so.6(cfree+0x90)[0x17e0f0]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x24e06f1]
./a.out(__gxx_personality_v0+0x31b)[0x80488e7]
./a.out[0x804957b]
/lib/libc.so.6(__libc_start_main+0xe0)[0x127390]
./a.out(__gxx_personality_v0+0x45)[0x8048611]
======= Memory map: ========
00110000-00111000 r-xp 00110000 00:00 0          [vdso]
00111000-00264000 r-xp 00000000 fd:00 1067801    /lib/libc-2.7.so
00264000-00266000 r-xp 00153000 fd:00 1067801    /lib/libc-2.7.so
00266000-00267000 rwxp 00155000 fd:00 1067801    /lib/libc-2.7.so
00267000-0026a000 rwxp 00267000 00:00 0
00296000-002b1000 r-xp 00000000 fd:00 1067800    /lib/ld-2.7.so
002b1000-002b2000 r-xp 0001a000 fd:00 1067800    /lib/ld-2.7.so
002b2000-002b3000 rwxp 0001b000 fd:00 1067800    /lib/ld-2.7.so
00d68000-00d8f000 r-xp 00000000 fd:00 1067805    /lib/libm-2.7.so
00d8f000-00d90000 r-xp 00026000 fd:00 1067805    /lib/libm-2.7.so
00d90000-00d91000 rwxp 00027000 fd:00 1067805    /lib/libm-2.7.so
0242d000-0250d000 r-xp 00000000 fd:00 227099     /usr/lib/libstdc++.so.6.0.8
0250d000-02511000 r-xp 000df000 fd:00 227099     /usr/lib/libstdc++.so.6.0.8
02511000-02512000 rwxp 000e3000 fd:00 227099     /usr/lib/libstdc++.so.6.0.8
02512000-02518000 rwxp 02512000 00:00 0
07fe6000-07ff1000 r-xp 00000000 fd:00 1067812    /lib/libgcc_s-4.1.2-20070925.so.1
07ff1000-07ff2000 rwxp 0000a000 fd:00 1067812    /lib/libgcc_s-4.1.2-20070925.so.1
08048000-0804a000 r-xp 00000000 fd:00 1202293    /home/liuhy/c/9/a.out
0804a000-0804b000 rw-p 00001000 fd:00 1202293    /home/liuhy/c/9/a.out
08460000-08481000 rw-p 08460000 00:00 0
b7e00000-b7e21000 rw-p b7e00000 00:00 0
b7e21000-b7f00000 ---p b7e21000 00:00 0
b7fd8000-b7fda000 rw-p b7fd8000 00:00 0
b7feb000-b7fec000 rw-p b7feb000 00:00 0
bff3a000-bff4f000 rw-p bffea000 00:00 0          [stack]
已放弃

论坛徽章:
0
2 [报告]
发表于 2008-05-25 01:20 |只看该作者

检查free操作

都double free 了

看看是不是 一个指针free了两次,第二次为 null 时 free 就崩了

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
3 [报告]
发表于 2008-05-25 09:24 |只看该作者
valgrind
查一下

论坛徽章:
0
4 [报告]
发表于 2008-05-25 11:28 |只看该作者
原帖由 笑面狐 于 2008-5-25 01:20 发表
都double free 了

看看是不是 一个指针free了两次,第二次为 null 时 free 就崩了


我的构造函数和析构函数是这样的,详细请参照另一贴:http://bbs.chinaunix.net/thread-1103739-1-2.html


matrix::matrix(short vrow,short vcol) {
        row = vrow;
        col = vcol;
        elems = new double[row * col];
}
matrix::matrix(matrix const &m) {
        row = m.row;
        col = m.col;
        elems = new double[row * col];
        for(int j = 0; j< row * col ; j++) {
                elems[j]=m.elems[j];
        }
}
matrix::~matrix() {
        delete elems;
}

没看到哪里有free两次啊。

[ 本帖最后由 welcome008 于 2008-5-29 11:03 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2008-05-25 11:36 |只看该作者
原帖由 flw 于 2008-5-25 09:24 发表
valgrind
查一下


只是看到说free() /delete /delete [] 不匹配
可是我的构造函数与析构函数都有啊:

matrix::matrix(short vrow,short vcol) {
        row = vrow;
        col = vcol;
        elems = new double[row * col];
}
matrix::matrix(matrix const &m) {
        row = m.row;
        col = m.col;
        elems = new double[row * col];
        for(int j = 0; j< row * col ; j++) {
                elems[j]=m.elems[j];
        }
}
matrix::~matrix() {
        delete []elems;
}

(详细请看另一篇帖子:http://bbs.chinaunix.net/thread-1103739-1-2.html,是关于一个矩阵的加减乘运算的)
valgrind --tool=memcheck --leak-check=full ./a.out
==18635== Memcheck, a memory error detector.
==18635== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==18635== Using LibVEX rev 1732, a library for dynamic binary translation.
==18635== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==18635== Using valgrind-3.2.3, a dynamic binary instrumentation framework.
==18635== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==18635== For more details, rerun with: -v
==18635==
==18635== Mismatched free() / delete / delete []
==18635==    at 0x4004E56: operator delete(void*) (vg_replace_malloc.c:244)
==18635==    by 0x80488E6: matrix::~matrix() (matrix.cpp:33)
==18635==    by 0x80492D2: main (matrix.cpp:124)
==18635==  Address 0x4176458 is 0 bytes inside a block of size 96 alloc'd
==18635==    at 0x400595C: operator new[](unsigned) (vg_replace_malloc.c:195)
==18635==    by 0x8048A6D: matrix::matrix(short, short) (matrix.cpp:22)
==18635==    by 0x8048CB4: operator+(matrix, matrix) (matrix.cpp:54)
==18635==    by 0x80492B8: main (matrix.cpp:124)
==18635==
==18635== Mismatched free() / delete / delete []
==18635==    at 0x4004E56: operator delete(void*) (vg_replace_malloc.c:244)
==18635==    by 0x80488E6: matrix::~matrix() (matrix.cpp:33)
==18635==    by 0x80492DD: main (matrix.cpp:124)
==18635==  Address 0x41763C8 is 0 bytes inside a block of size 96 alloc'd
==18635==    at 0x400595C: operator new[](unsigned) (vg_replace_malloc.c:195)
==18635==    by 0x8048941: matrix::matrix(matrix const& (matrix.cpp:27)
==18635==    by 0x804929F: main (matrix.cpp:124)
==18635==
==18635== Mismatched free() / delete / delete []
==18635==    at 0x4004E56: operator delete(void*) (vg_replace_malloc.c:244)
==18635==    by 0x80488E6: matrix::~matrix() (matrix.cpp:33)
==18635==    by 0x80492E8: main (matrix.cpp:124)
==18635==  Address 0x4176338 is 0 bytes inside a block of size 96 alloc'd
==18635==    at 0x400595C: operator new[](unsigned) (vg_replace_malloc.c:195)
==18635==    by 0x8048941: matrix::matrix(matrix const& (matrix.cpp:27)
==18635==    by 0x804928D: main (matrix.cpp:124)
==18635==
==18635== Invalid read of size 8
==18635==    at 0x8048879: matrix::print() (matrix.cpp:3
==18635==    by 0x80492F3: main (matrix.cpp:125)
==18635==  Address 0x4176458 is 0 bytes inside a block of size 96 free'd
==18635==    at 0x4004E56: operator delete(void*) (vg_replace_malloc.c:244)
==18635==    by 0x80488E6: matrix::~matrix() (matrix.cpp:33)
==18635==    by 0x80492D2: main (matrix.cpp:124)
2       4       6       8
10      12      14      16
18      20      22      24
----------------
==18635==
==18635== Mismatched free() / delete / delete []
==18635==    at 0x4004E56: operator delete(void*) (vg_replace_malloc.c:244)
==18635==    by 0x80488E6: matrix::~matrix() (matrix.cpp:33)
==18635==    by 0x8049340: main (matrix.cpp:126)
==18635==  Address 0x41762A8 is 0 bytes inside a block of size 96 alloc'd
==18635==    at 0x400595C: operator new[](unsigned) (vg_replace_malloc.c:195)
==18635==    by 0x8048A6D: matrix::matrix(short, short) (matrix.cpp:22)
==18635==    by 0x8048E31: main (matrix.cpp:87)
==18635==
==18635== Mismatched free() / delete / delete []
==18635==    at 0x4004E56: operator delete(void*) (vg_replace_malloc.c:244)
==18635==    by 0x80488E6: matrix::~matrix() (matrix.cpp:33)
==18635==    by 0x804934B: main (matrix.cpp:126)
==18635==  Address 0x4176238 is 0 bytes inside a block of size 64 alloc'd
==18635==    at 0x400595C: operator new[](unsigned) (vg_replace_malloc.c:195)
==18635==    by 0x8048A6D: matrix::matrix(short, short) (matrix.cpp:22)
==18635==    by 0x8048E16: main (matrix.cpp:87)
==18635==
==18635== Invalid free() / delete / delete[]
==18635==    at 0x4004E56: operator delete(void*) (vg_replace_malloc.c:244)
==18635==    by 0x80488E6: matrix::~matrix() (matrix.cpp:33)
==18635==    by 0x8049356: main (matrix.cpp:126)
==18635==  Address 0x4176458 is 0 bytes inside a block of size 96 free'd
==18635==    at 0x4004E56: operator delete(void*) (vg_replace_malloc.c:244)
==18635==    by 0x80488E6: matrix::~matrix() (matrix.cpp:33)
==18635==    by 0x80492D2: main (matrix.cpp:124)
==18635==
==18635== Mismatched free() / delete / delete []
==18635==    at 0x4004E56: operator delete(void*) (vg_replace_malloc.c:244)
==18635==    by 0x80488E6: matrix::~matrix() (matrix.cpp:33)
==18635==    by 0x8049361: main (matrix.cpp:126)
==18635==  Address 0x4176148 is 0 bytes inside a block of size 48 alloc'd
==18635==    at 0x400595C: operator new[](unsigned) (vg_replace_malloc.c:195)
==18635==    by 0x8048A6D: matrix::matrix(short, short) (matrix.cpp:22)
==18635==    by 0x8048DE0: main (matrix.cpp:87)
==18635==
==18635== Mismatched free() / delete / delete []
==18635==    at 0x4004E56: operator delete(void*) (vg_replace_malloc.c:244)
==18635==    by 0x80488E6: matrix::~matrix() (matrix.cpp:33)
==18635==    by 0x804936C: main (matrix.cpp:126)
==18635==  Address 0x41760B8 is 0 bytes inside a block of size 96 alloc'd
==18635==    at 0x400595C: operator new[](unsigned) (vg_replace_malloc.c:195)
==18635==    by 0x8048A6D: matrix::matrix(short, short) (matrix.cpp:22)
==18635==    by 0x8048DC5: main (matrix.cpp:87)
==18635==
==18635== Mismatched free() / delete / delete []
==18635==    at 0x4004E56: operator delete(void*) (vg_replace_malloc.c:244)
==18635==    by 0x80488E6: matrix::~matrix() (matrix.cpp:33)
==18635==    by 0x8049377: main (matrix.cpp:126)
==18635==  Address 0x4176028 is 0 bytes inside a block of size 96 alloc'd
==18635==    at 0x400595C: operator new[](unsigned) (vg_replace_malloc.c:195)
==18635==    by 0x8048A6D: matrix::matrix(short, short) (matrix.cpp:22)
==18635==    by 0x8048DAA: main (matrix.cpp:87)
==18635==
==18635== ERROR SUMMARY: 21 errors from 10 contexts (suppressed: 16 from 1)
==18635== malloc/free: in use at exit: 96 bytes in 1 blocks.
==18635== malloc/free: 9 allocs, 9 frees, 784 bytes allocated.
==18635== For counts of detected errors, rerun with: -v
==18635== searching for pointers to 1 not-freed blocks.
==18635== checked 87,644 bytes.
==18635==
==18635==
==18635== 96 bytes in 1 blocks are definitely lost in loss record 1 of 1
==18635==    at 0x400595C: operator new[](unsigned) (vg_replace_malloc.c:195)
==18635==    by 0x8048A6D: matrix::matrix(short, short) (matrix.cpp:22)
==18635==    by 0x8048DFB: main (matrix.cpp:87)
==18635==
==18635== LEAK SUMMARY:
==18635==    definitely lost: 96 bytes in 1 blocks.
==18635==      possibly lost: 0 bytes in 0 blocks.
==18635==    still reachable: 0 bytes in 0 blocks.
==18635==         suppressed: 0 bytes in 0 blocks.

[ 本帖最后由 welcome008 于 2008-5-29 11:02 编辑 ]

论坛徽章:
1
双子座
日期:2015-01-04 14:25:06
6 [报告]
发表于 2008-05-26 09:22 |只看该作者
elems = new double[row * col];
delete elems;
这两个不匹配
delete []elems;

论坛徽章:
0
7 [报告]
发表于 2008-05-26 15:56 |只看该作者
原帖由 yecheng_110 于 2008-5-26 09:22 发表
elems = new double[row * col];
delete elems;
这两个不匹配
delete []elems;


多谢,我改了,仍然报错:
2       4       6       8
10      12      14      16
18      20      22      24
----------------
*** glibc detected *** ./a.out: double free or corruption (out): 0x09d5b2f8 ***
======= Backtrace: =========
/lib/libc.so.6[0x17aac1]
/lib/libc.so.6(cfree+0x90)[0x17e0f0]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0x24e06f1]
/usr/lib/libstdc++.so.6(_ZdaPv+0x1d)[0x24e074d]
./a.out(__gxx_personality_v0+0x324)[0x80488f0]
./a.out[0x8049367]
/lib/libc.so.6(__libc_start_main+0xe0)[0x127390]
./a.out(__gxx_personality_v0+0x45)[0x8048611]
======= Memory map: ========
00110000-00111000 r-xp 00110000 00:00 0          [vdso]
00111000-00264000 r-xp 00000000 fd:00 1067801    /lib/libc-2.7.so
00264000-00266000 r-xp 00153000 fd:00 1067801    /lib/libc-2.7.so
00266000-00267000 rwxp 00155000 fd:00 1067801    /lib/libc-2.7.so
00267000-0026a000 rwxp 00267000 00:00 0
00296000-002b1000 r-xp 00000000 fd:00 1067800    /lib/ld-2.7.so
002b1000-002b2000 r-xp 0001a000 fd:00 1067800    /lib/ld-2.7.so
002b2000-002b3000 rwxp 0001b000 fd:00 1067800    /lib/ld-2.7.so
00d68000-00d8f000 r-xp 00000000 fd:00 1067805    /lib/libm-2.7.so
00d8f000-00d90000 r-xp 00026000 fd:00 1067805    /lib/libm-2.7.so
00d90000-00d91000 rwxp 00027000 fd:00 1067805    /lib/libm-2.7.so
0242d000-0250d000 r-xp 00000000 fd:00 227099     /usr/lib/libstdc++.so.6.0.8
0250d000-02511000 r-xp 000df000 fd:00 227099     /usr/lib/libstdc++.so.6.0.8
02511000-02512000 rwxp 000e3000 fd:00 227099     /usr/lib/libstdc++.so.6.0.8
02512000-02518000 rwxp 02512000 00:00 0
07fe6000-07ff1000 r-xp 00000000 fd:00 1067812    /lib/libgcc_s-4.1.2-20070925.so.1
07ff1000-07ff2000 rwxp 0000a000 fd:00 1067812    /lib/libgcc_s-4.1.2-20070925.so.1
08048000-0804a000 r-xp 00000000 fd:00 1202293    /home/liuhy/c/9/a.out
0804a000-0804b000 rw-p 00001000 fd:00 1202293    /home/liuhy/c/9/a.out
09d5b000-09d7c000 rw-p 09d5b000 00:00 0
b7e00000-b7e21000 rw-p b7e00000 00:00 0
b7e21000-b7f00000 ---p b7e21000 00:00 0
b7fdd000-b7fdf000 rw-p b7fdd000 00:00 0
b7ff0000-b7ff1000 rw-p b7ff0000 00:00 0
bff0b000-bff20000 rw-p bffea000 00:00 0          [stack]
已放弃

论坛徽章:
0
8 [报告]
发表于 2008-05-27 16:08 |只看该作者
我把这个再翻一下

我看过redhat有说,可以通过设置环境变量避免这个报错:

但是我想知道到底是哪里出了问题
我又没有重复析构,
为什么呐?

论坛徽章:
0
9 [报告]
发表于 2008-05-28 16:25 |只看该作者
我再翻一下
通过设置环境变量:MALLOC_CHECK_=0
是没有报错了

但是怎么就看不出程序的问题呢?

哪位比较有时间也调试一下,谢谢!

论坛徽章:
0
10 [报告]
发表于 2008-05-28 23:47 |只看该作者

回复 #1 welcome008 的帖子

不要用这样的方法来掩盖你程序的错误。。。。

matrix::matrix(matrix const &m) {
        row = m.row;
        col = m.col;
        elems = new double[row * col];
        for(int i = 0; i< row * col ; i++) {
                elems=m.elems;
        }
}

这里new出来的elems,又被赋予其他值了,你怎么去delete掉它?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP