0

我正在使用 valarray 类,我收到以下错误:

    *** glibc detected *** /pathaToMyProject/Debug/BoundaryElements: free(): invalid pointer: 0x0000000000608dd0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7f40bb272b96]
======= Memory map: ========
00400000-00408000 r-xp 00000000 08:01 80874818           
00608000-00609000 r--p 00008000 08:01 80874818           
00609000-0060a000 rw-p 00009000 08:01 80874818           
00ee3000-00f04000 rw-p 00000000 00:00 0                                  [heap]
7f40bb1f4000-7f40bb3a9000 r-xp 00000000 08:01 81527681                   /lib/x86_64-linux-gnu/libc-2.15.so
7f40bb3a9000-7f40bb5a8000 ---p 001b5000 08:01 81527681                   /lib/x86_64-linux-gnu/libc-2.15.so
7f40bb5a8000-7f40bb5ac000 r--p 001b4000 08:01 81527681                   /lib/x86_64-linux-gnu/libc-2.15.so
7f40bb5ac000-7f40bb5ae000 rw-p 001b8000 08:01 81527681                   /lib/x86_64-linux-gnu/libc-2.15.so
7f40bb5ae000-7f40bb5b3000 rw-p 00000000 00:00 0 
7f40bb5b3000-7f40bb5c8000 r-xp 00000000 08:01 81530362                   /lib/x86_64-linux-gnu/libgcc_s.so.1
7f40bb5c8000-7f40bb7c7000 ---p 00015000 08:01 81530362                   /lib/x86_64-linux-gnu/libgcc_s.so.1
7f40bb7c7000-7f40bb7c8000 r--p 00014000 08:01 81530362                   /lib/x86_64-linux-gnu/libgcc_s.so.1
7f40bb7c8000-7f40bb7c9000 rw-p 00015000 08:01 81530362                   /lib/x86_64-linux-gnu/libgcc_s.so.1
7f40bb7c9000-7f40bb8c4000 r-xp 00000000 08:01 81527692                   /lib/x86_64-linux-gnu/libm-2.15.so
7f40bb8c4000-7f40bbac3000 ---p 000fb000 08:01 81527692                   /lib/x86_64-linux-gnu/libm-2.15.so
7f40bbac3000-7f40bbac4000 r--p 000fa000 08:01 81527692                   /lib/x86_64-linux-gnu/libm-2.15.so
7f40bbac4000-7f40bbac5000 rw-p 000fb000 08:01 81527692                   /lib/x86_64-linux-gnu/libm-2.15.so
7f40bbac5000-7f40bbba7000 r-xp 00000000 08:01 45620408                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7f40bbba7000-7f40bbda6000 ---p 000e2000 08:01 45620408                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7f40bbda6000-7f40bbdae000 r--p 000e1000 08:01 45620408                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7f40bbdae000-7f40bbdb0000 rw-p 000e9000 08:01 45620408                   /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16
7f40bbdb0000-7f40bbdc5000 rw-p 00000000 00:00 0 
7f40bbdc5000-7f40bbde7000 r-xp 00000000 08:01 81530272                   /lib/x86_64-linux-gnu/ld-2.15.so
7f40bbfbc000-7f40bbfc1000 rw-p 00000000 00:00 0 
7f40bbfe4000-7f40bbfe7000 rw-p 00000000 00:00 0 
7f40bbfe7000-7f40bbfe8000 r--p 00022000 08:01 81530272                   /lib/x86_64-linux-gnu/ld-2.15.so
7f40bbfe8000-7f40bbfea000 rw-p 00023000 08:01 81530272                   /lib/x86_64-linux-gnu/ld-2.15.so
7fffe821b000-7fffe823c000 rw-p 00000000 00:00 0                          [stack]
7fffe8331000-7fffe8332000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]

当我使用复制构造函数时,这个错误发生在这一点上:

Coords(const Coords& coord){
    this->order = coord.order;
    this->x = coord.x;
    this->y = coord.y;
    this->node = new unsigned int[order + 1];
    for (int ii = 0; ii < (order + 1); ii++) this->node[ii] = coord.node[ii];
    this->reg = coord.reg;
}

请问我该如何解决?我看过很多地方,发现可以使用 Valgrind,但我想这不是必需的,因为我使用的是 std 类。

4

0 回答 0