Glibc bug?

George Katsirelos gkatsi at cs.toronto.edu
Sat Feb 23 20:16:00 EET 2002


Dimitris Kamenopoulos wrote:

>On Saturday 23 February 2002 15:58, Dimitrios Stasinopoulos wrote:
>
>>Hello All!
>>
>>Opoios brei ti ginetai edo, mpainei sto AUTHORS :o)
>>
>>Exoume ton constructor tis class Question:
>>
>>Question::Question(char * question)
>>{
>>int size=15;
>>char * label=0;
>>
>>cout << "Question::Question()" << endl;
>>
>>label=(char *)malloc(size+1);
>>	if(label)
>>	{
>>	memset(label, 0, size+1);
>>	free(label);
>>	label=0;
>>	}
>>}
>>
>An to evlepe auto pantws o Bjarne, mallon 8a frikare. Giati malloc-free, kai 
>oxi new-delete? Giati char * kai oxi string (estw string *)?  Giati memset 
>kai oxi for (...) label[i]=0? Mplekeis me poly xamhles domes kai ousiastika 
>grafeis C, oxi C++. Ektos an kaneis kati poly xamhlou epipedou, kalytera 
>einai na anhsyxei o compiler gia to pws 8a gemisei pio apotelesmatika ena 
>string me mhdenika. Pantws an estelnes ligo perissotero kwdika (p.x. olon ton 
>kwdika ths klashs Question gia arxh) 8a mporousame kai na voh8hsoume 
>perissotero.
>
>

Mallon 8a frikare kai me to string*, giati protimotero einai to string& 
h string const & h an pragmati xreiazetai pointer, tote kalytera smart 
pointer (px boost::shared_ptr). Kai efoson ayto pou kaneis allocate 8es 
na to kaneis free meta, isws kalytera na xrhsimopoihseis to 
boost::scoped_array. H akoma kalytera vector<char> h string.

Epishs to for den protimatai. Kalytero einai to std::fill, to opoio se 
kales ylopoihseis ths STL exei specializations wste se ayth thn 
periptwsh na kanei ena memset kai na einai to idio grhgoro me ton 
antistoixo C kwdika (h toulaxiston etsi elpizeis, an o c++ compiler sou 
mporei na xeiristei swsta to inlining ths STL)

Oso gia thn arxikh erwthsh: To pi8anotero einai oti kapoio allo kommati 
tou kwdika prokalei heap corruption. Apo oti fainetai apo to backtrace 
tou gdb, to core to petaei to free, to opoio epibebaiwnei ayth thn 
ypo8esh. Oso gia to giati douleyei an baleis deytero malloc, apla to 
corruption tou heap brisketai sto prwto chunk pou kaneis allocate, enw 
to deytero einai mia xara. An baleis kai deytero free, opws prepei, 8a 
pareis kai pali ena core, opws prepei. Dokimase to Electric Fence gia na 
breis pou brisketai to la8os.


(sorry ston dhmhtrh gia to diplo mail)





More information about the Linux-greek-users mailing list