From: ernomat AT evitech DOT fi (Erno Tuomainen) Newsgroups: comp.os.msdos.djgpp Subject: Odd behaviour C++ or a BUG ? (class destructor) Date: Tue, 03 Feb 1998 22:48:00 GMT Organization: EVITech, Espoo/Finland. Lines: 129 Message-ID: <34d89ce5.11989788@news.freenet.hut.fi> NNTP-Posting-Host: dialin-0-20.evitech.fi Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Hi! I am using DJGPP 2.01 (GCC 2.7.2.1) and am having a very ODD problem with my Message-class. (It's a class in my roguelike game handling the text message queue). I won't post the whole code here, just the portion which is causing problems. Explanation: Below is the destructor for the Message-class I am having problems with. After installing Fortify V2.2 it started to complain that the memory allocated by my Message-class is not deallocated on exit. If I am correct, the destructor will be called automatically when the program exits? And it is, I've checked this by including some debugging messages to the code below, it gets called at the end of the program. BUT! This does not free the memory as it should. Am I missing something here? I have another routine, which is EXACTLY like this destructor, but named as "void Message::clearall(void)". If I *MANUALLY* call this routine at the end of my program, everything gets cleaned. /************************/ /* the class destructor */ /************************/ Message::~Message() { Tmsgpointer aux, tmp; aux=msglist; while(aux) { tmp=aux; aux=aux->next; /* clear the message */ delete [] tmp->msg; /* delete node */ delete tmp; } msglist=NULL; shownext=NULL; updcount=0; lastadded=NULL; count=0; } /********************************/ /* here is the clearall routine */ /********************************/ void Message::clearall(void) { Tmsgpointer aux, tmp; aux=msglist; while(aux) { tmp=aux; aux=aux->next; /* clear the message */ delete [] tmp->msg; /* delete node */ delete tmp; } msglist=NULL; shownext=NULL; updcount=0; lastadded=NULL; count=0; } HELP, I am clueless. There is either a bad bug in a) my program b) DJGPP or *I AM* missing something I should know. Here is the class header file (message.h) so you can check it too. /* message.h for Legend of Saladir ** (C)1997/1998 by Erno Tuomainen ** ** header for message.cpp */ // max number of messages to hold in the buffer #define MSG_MAXNUM 60 typedef struct _msginfo *Tmsgpointer; typedef Tmsgpointer Tmsglist; typedef struct _msginfo { char *msg; Tmsgpointer next; } Tmessage; class Message { private: Tmsglist msglist; Tmsgpointer shownext; Tmsgpointer lastadded; int8u count; int8u index; int16s lastx; int16s lasty; public: Message(); ~Message(); void newmsg(char *, int16u); void clearall(void); void notice(void); void showlast(void); void update(bool); void showall(void); void waitformorekey(void); /* wait for ENTER or PADENTER */ void setdelay(int16u); /* set a delay for printing */ }; --- Erno Tuomainen -+- A Computer Engineering student at Helsinki/Finland + ernomat AT evitech DOT fi at www.evitech.fi/~ernomat +