- 论坛徽章:
- 0
|
原帖由 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 编辑 ] |
|