0

I am using valarray class and I get the following error:

    *** 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]

And this error happens ate this point, when I use the copy constructor:

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;
}

How can I solve it, please? I've looked at many places and I found that I could use Valgrind, but I guess this is not necessary, since I am using a std class.

Gabs
  • 292
  • 5
  • 23
  • That's not a "point", but 6 lines. Tried a debugger? – Frank Osterfeld Jul 25 '13 at 13:19
  • Yes, I did. Have no idea of what is going on... – Gabs Jul 25 '13 at 13:54
  • So in which line exactly does it crash? And valgrind would indeed help, I guess. – Frank Osterfeld Jul 25 '13 at 18:38
  • I guess it has to do with the copy constructor of valarray. I did a deep debugging in the program, and the problem happens when the valarray copy constructor is called. – Gabs Jul 26 '13 at 14:40
  • The problem is in this line, in valarray copy constructor: 'if (_M_size == __v._M_size) std::__valarray_copy(__v._M_data, _M_size, _M_data);' Apparently, _M_size and _M_data are empty, when the program. The most strange thing is that it doesn't always happens , since I have other parts of the code that uses the same constructor and they just work fine... – Gabs Jul 26 '13 at 14:49

0 Answers0