Új hozzászólás Aktív témák

  • Gyuri16

    senior tag

    válasz dani0907 #1049 üzenetére

    megneztem valgrind-dal ( valgrind --leak-check=yes -v ./strc ), eredmeny:

    ==6235== 871 errors in context 1 of 1:
    ==6235== Mismatched free() / delete / delete []
    ==6235== at 0x4023881: operator delete(void*) (vg_replace_malloc.c:387)
    ==6235== by 0x8048D80: stringc::operator=(stringc) (stringc.hpp:61)
    ==6235== by 0x8048F98: load(_IO_FILE*, stringc) (stringc.hpp:103)
    ==6235== by 0x8049073: test_1() (strc.cpp:17)
    ==6235== by 0x80491C0: main (strc.cpp:42)
    ==6235== Address 0x42c5f20 is 0 bytes inside a block of size 1 alloc'd
    ==6235== at 0x40243B0: operator new[](unsigned int) (vg_replace_malloc.c:299)
    ==6235== by 0x8048C46: stringc::stringc(stringc const&) (stringc.hpp:46)
    ==6235== by 0x804905A: test_1() (strc.cpp:17)
    ==6235== by 0x80491C0: main (strc.cpp:42)

    (sorszamok nem fognak egyezni, mert kivettem belole az ifdefeket)

    ebben a fuggvenyben:

    stringc stringc::operator=(stringc s){
    if(this == &s)
    return *this; //önmagába nem másol
    delete p;
    h=s.h;
    p= new char[h+1];assert(p!=0);
    strcpy(p,s.p);
    return *this;
    }

    delete p; helyett delete [] p; kell.

Új hozzászólás Aktív témák

Hirdetés