Re: free() crash

From: Sean Butler (sbutler@DEVEAST.COM)
Date: 02/02/98


In a structure I have two members,
 char * titlem[ LVL_IMPL + 1 ];
 char * titlef[ LVL_IMPL + 1 ];

At one point I wish to free them, and I do so like this :

  for( i = 0; i <= LVL_IMPL ; i++ )
   {
    if( cls->titlem[ i ] ) free( cls->titlem[ i ] );
    if( cls->titlem[ i ] ) free( cls->titlem[ i ] );
   }
---------------------------------------------------------------------

Well, I hate to state the obvious, but you never know:
1.) Are the elements of titlem allocated with malloc or its cousins?
2.) Do you initialize the array to all NULL first to be sure you don't
        try to free a garbage pointer?
3.) Have you #included <stdlib.h>?
4.) When you free a pointer you should be sure to set it to NULL
        so that you dont try to free it again.

Hope those ideas help.
--Sean


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST