Login
User Name:

Password:



Register

Forgot your password?
AFKMud 2.2.4
Dec 10, 2024 4:09 pm
By Samson
I3 and IMC
Dec 8, 2024 6:35 pm
By Remcon
Hi - Clean SmaugFuss map/description issue..
Dec 6, 2024 11:54 am
By Remcon
Ubuntu 22.04.5 LTS
Dec 5, 2024 5:10 pm
By Remcon
SmaugFUSS 1.8/1.9
Nov 29, 2024 11:46 am
By Remcon
SWFOTEFUSS 1.5.1
Author: Various
Submitted by: Samson
SWRFUSS 1.4.1
Author: Various
Submitted by: Samson
SmaugFUSS 1.9.5
Author: Various
Submitted by: Samson
AFKMud 2.2.4
Author: AFKMud Team
Submitted by: Samson
LOP 1.5
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl, Bing, AhrefsBot

Members: 0
Guests: 217
Stats
Files
Topics
Posts
Members
Newest Member
494
3,808
19,706
589
Grover9624

Today's Birthdays
There are no member birthdays today.
» SmaugMuds » Codebases » SmaugFUSS » cleanup_memory
Forum Rules | Mark all | Recent Posts

cleanup_memory
< Newer Topic :: Older Topic > for smaugfuss

Pages:<< prev 1, 2 next >>
Post is unread #1 Aug 20, 2005 7:03 pm   
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,946
JoinedJul 26, 2005

 
Hope I included it all for stock smaug, only doing this since some may find it easier to use this then trying to locate all the functions and all theirself :) good luck :)
in comm.c
find
const char echo_off_str[] = { IAC, WILL, TELOPT_ECHO, '\0' };
const char echo_on_str[] = { IAC, WONT, TELOPT_ECHO, '\0' };
const char go_ahead_str[] = { IAC, GA, '\0' };

Above or below that add
#ifdef IMC
void imc_delete_info( void );
void free_imcdata( bool complete );
#endif
void dispose_ban( BAN_DATA * ban, int type );
void close_all_areas( void );
void free_commands( void );
void free_prog_actlists( void );
void free_boards( void );
void free_skills( void );
void free_socials( void );
void free_teleports( void );
void free_tongues( void );
void free_helps( void );
void free_watchlist( void );
void free_projects( void );
void free_bans( void );
void free_clans( void );
void free_morphs( void );
void free_deities( void );


Find
#ifdef WIN32
int mainthread( int argc, char **argv )
#else
int main( int argc, char **argv )
#endif

above that add
/*
 * Clean all memory on exit to help find leaks
 * Yeah I know, one big ugly function -Druid
 * Added to AFKMud by Samson on 5-8-03.
 */
void cleanup_memory( void )
{
   int hash, loopa;
#ifdef OLD_CRYPT
   char *cryptstr;
#endif
   CHAR_DATA *character;
   OBJ_DATA *object;
   DESCRIPTOR_DATA *desc, *desc_next;

#ifdef IMC
   fprintf( stdout, "%s", "IMC2 Data.\n" );
   free_imcdata( TRUE );
   imc_delete_info(  );
#endif
#ifdef I3
   fprintf( stdout, "%s", "I3 Data.\n" );
   free_i3data( TRUE );
   destroy_I3_mud( this_i3mud );
#endif

   fprintf( stdout, "%s", "Project Data.\n" );
   free_projects(  );

   fprintf( stdout, "%s", "Ban Data.\n" );
   free_bans(  );

   fprintf( stdout, "%s", "Morph Data.\n" );
   free_morphs(  );

   /*
    * Commands
    */
   fprintf( stdout, "%s", "Commands.\n" );
   free_commands(  );

#ifdef MULTIPORT
   /*
    * Shell Commands
    */
   fprintf( stdout, "%s", "Shell Commands.\n" );
   free_shellcommands(  );
#endif

   /*
    * Deities
    */
   fprintf( stdout, "%s", "Deities.\n" );
   free_deities(  );

   /*
    * Clans
    */
   fprintf( stdout, "%s", "Clans.\n" );
   free_clans(  );

   /*
    * socials
    */
   fprintf( stdout, "%s", "Socials.\n" );
   free_socials(  );

   /*
    * Watches
    */
   fprintf( stdout, "%s", "Watches.\n" );
   free_watchlist(  );

   /*
    * Helps
    */
   fprintf( stdout, "%s", "Helps.\n" );
   free_helps(  );

   /*
    * Languages
    */
   fprintf( stdout, "%s", "Languages.\n" );
   free_tongues(  );

   /*
    * Boards
    */
   fprintf( stdout, "%s", "Boards.\n" );
   free_boards(  );

   /*
    * Whack supermob
    */
   fprintf( stdout, "%s", "Whacking supermob.\n" );
   if( supermob )
   {
      char_from_room( supermob );
      UNLINK( supermob, first_char, last_char, next, prev );
      free_char( supermob );
   }

   /*
    * Free Objects
    */
   clean_obj_queue(  );
   fprintf( stdout, "%s", "Objects.\n" );
   while( ( object = last_object ) != NULL )
      extract_obj( object );
   clean_obj_queue(  );

   /*
    * Free Characters
    */
   clean_char_queue(  );
   fprintf( stdout, "%s", "Characters.\n" );
   while( ( character = last_char ) != NULL )
      extract_char( character, TRUE );
   clean_char_queue(  );

   /*
    * Descriptors
    */
   fprintf( stdout, "%s", "Descriptors.\n" );
   for( desc = first_descriptor; desc; desc = desc_next )
   {
      desc_next = desc->next;
      UNLINK( desc, first_descriptor, last_descriptor, next, prev );
      free_desc( desc );
   }

   /*
    * Races
    */
   fprintf( stdout, "%s", "Races.\n" );
   for( hash = 0; hash < MAX_RACE; hash++ )
   {
      for( loopa = 0; loopa < MAX_WHERE_NAME; loopa++ )
         DISPOSE( race_table[hash]->where_name[loopa] );
      DISPOSE( race_table[hash] );
   }

   /*
    * Classes
    */
   fprintf( stdout, "%s", "Classes.\n" );
   for( hash = 0; hash < MAX_CLASS; hash++ )
   {
      STRFREE( class_table[hash]->who_name );
      DISPOSE( class_table[hash] );
   }

   /*
    * Teleport lists
    */
   fprintf( stdout, "%s", "Teleport Data.\n" );
   free_teleports(  );

   /*
    * Areas - this includes killing off the hash tables and such
    */
   fprintf( stdout, "%s", "Area Data Tables.\n" );
   close_all_areas(  );

   /*
    * Get rid of auction pointer  MUST BE AFTER OBJECTS DESTROYED
    */
   fprintf( stdout, "%s", "Auction.\n" );
   DISPOSE( auction );

   /*
    * System Data
    */
   fprintf( stdout, "%s", "System data.\n" );
   if( sysdata.time_of_max )
     DISPOSE( sysdata.time_of_max );
   if( sysdata.mud_name )
     DISPOSE( sysdata.mud_name );
   if( sysdata.guild_overseer )
     STRFREE( sysdata.guild_overseer );
   if( sysdata.guild_advisor )
     STRFREE( sysdata.guild_advisor );

   /*
    * Title table
    */
   fprintf( stdout, "%s", "Title table.\n" );
   for( hash = 0; hash < MAX_CLASS; hash++ )
   {
      for( loopa = 0; loopa < MAX_LEVEL + 1; loopa++ )
      {
         DISPOSE( title_table[hash][loopa][0] );
         DISPOSE( title_table[hash][loopa][1] );
      }
   }

   /*
    * Skills
    */
   fprintf( stdout, "%s", "Skills and Herbs.\n" );
   free_skills(  );

   /*
    * Prog Act lists
    */
   fprintf( stdout, "%s", "Mudprog act lists.\n" );
   free_prog_actlists(  );

   /*
    * Some freaking globals
    */
   fprintf( stdout, "%s", "Globals.\n" );
   DISPOSE( ranged_target_name );

#ifdef OLD_CRYPT
   fprintf( stdout, "%s", "Disposing of crypt.\n" );
   cryptstr = crypt( "cleaning", "$1$Cleanup" );
   free( cryptstr );
#endif

   fprintf( stdout, "%s", "Checking string hash for leftovers.\n" );
   {
      for( hash = 0; hash < 1024; hash++ )
         hash_dump( hash );
   }

   fprintf( stdout, "%s", "Cleanup complete, exiting.\n" );
   return;
}  /* cleanup memory */

find this towards the end of main function
   /*
    * That's all, folks.
    */
   log_string( "Normal termination of game." );

   exit( 0 );
   return 0;
}

change it to this
   /*
    * That's all, folks.
    */
   log_string( "Normal termination of game." );

   log_string("Cleaning up Memory.");
   cleanup_memory();

   exit( 0 );
   return 0;
}

in boards.c
find
bool is_note_to args( ( CHAR_DATA * ch, NOTE_DATA * pnote ) );
void note_attach args( ( CHAR_DATA * ch ) );
void note_remove args( ( CHAR_DATA * ch, BOARD_DATA * board, NOTE_DATA * pnote ) );
void do_note args( ( CHAR_DATA * ch, char *arg_passed, bool IS_MAIL ) );

below that add
void delete_project( PROJECT_DATA * project )
{
   NOTE_DATA *nlog, *tlog;

   nlog = project->last_log;
   while( nlog )
   {
      UNLINK( nlog, project->first_log, project->last_log, next, prev );
      tlog = nlog->prev;
      free_note( nlog );
      nlog = tlog;
   }
   STRFREE( project->coder );
   DISPOSE( project->description );
   DISPOSE( project->name );
   STRFREE( project->owner );
   DISPOSE( project->status );
   UNLINK( project, first_project, last_project, next, prev );
   DISPOSE( project );
}

void free_projects( void )
{
   PROJECT_DATA *project, *project_next;

   for( project = first_project; project; project = project_next )
   {
      project_next = project->next;
      delete_project( project );
   }
   return;
}

find
bool can_post( CHAR_DATA * ch, BOARD_DATA * board )
{
   /*
    * If your trust is high enough, you can post.
    */
   if( get_trust( ch ) >= board->min_post_level )
      return TRUE;

   /*
    * Your trust wasn't high enough, so check if a post_group has been set up.
    */
   if( board->post_group[0] != '\0' )
   {
      if( ch->pcdata->clan && !str_cmp( ch->pcdata->clan->name, board->post_group ) )
         return TRUE;
      if( ch->pcdata->council && !str_cmp( ch->pcdata->council->name, board->post_group ) )
         return TRUE;
   }
   return FALSE;
}

below that add
void free_board( BOARD_DATA * board )
{
   NOTE_DATA *pnote, *next_note;

   DISPOSE( board->extra_readers );
   DISPOSE( board->extra_removers );
   DISPOSE( board->read_group );
   DISPOSE( board->post_group );
   DISPOSE( board->extra_readers );
   DISPOSE( board->extra_removers );
   DISPOSE( board->note_file );
   DISPOSE( board->otakemessg );
   DISPOSE( board->ocopymessg );
   DISPOSE( board->oreadmessg );
   DISPOSE( board->oremovemessg );
   DISPOSE( board->olistmessg );
   DISPOSE( board->opostmessg );
   DISPOSE( board->postmessg );

   for( pnote = board->first_note; pnote; pnote = next_note )
   {
      next_note = pnote->next;
      UNLINK( pnote, board->first_note, board->last_note, next, prev );
      free_note( pnote );
   }
   UNLINK( board, first_board, last_board, next, prev );
   DISPOSE( board );
}

void free_boards( void )
{
   BOARD_DATA *board, *board_next;

   for( board = first_board; board; board = board_next )
   {
      board_next = board->next;
      free_board( board );
   }
   return;
}


in handler.c
find
/*
 * Give an obj to a char.
 */
OBJ_DATA *obj_to_char( OBJ_DATA * obj, CHAR_DATA * ch )

above that add this
void free_teleports( void )
{
   TELEPORT_DATA *tele, *tele_next;

   for( tele = first_teleport; tele; tele = tele_next )
   {
      tele_next = tele->next;

      UNLINK( tele, first_teleport, last_teleport, next, prev );
      DISPOSE( tele );
   }
}


in ban.c
find
void free_ban( BAN_DATA * pban )
{
   if( pban->name )
      DISPOSE( pban->name );
   if( pban->ban_time )
      DISPOSE( pban->ban_time );
   if( pban->note )
      STRFREE( pban->note );
   if( pban->ban_by )
      DISPOSE( pban->ban_by );
   DISPOSE( pban );
}

below that add
void free_bans( void )
{
   BAN_DATA *ban, *ban_next;

   for( ban = first_ban; ban; ban = ban_next )
   {
      ban_next = ban->next;
      dispose_ban( ban, BAN_SITE );
   }
   for( ban = first_ban_race; ban; ban = ban_next )
   {
      ban_next = ban->next;
      dispose_ban( ban, BAN_RACE );
   }
   for( ban = first_ban_class; ban; ban = ban_next )
   {
      ban_next = ban->next;
      dispose_ban( ban, BAN_CLASS );
   }
   return;
}


in polymorph.c
find
void free_morph( MORPH_DATA * morph )
{
   if( !morph )
      return;

   if( morph->damroll )
      DISPOSE( morph->damroll );
   if( morph->description )
      DISPOSE( morph->description );
   if( morph->help )
      DISPOSE( morph->help );
   if( morph->hit )
      DISPOSE( morph->hit );
   if( morph->hitroll )
      DISPOSE( morph->hitroll );
   if( morph->key_words )
      DISPOSE( morph->key_words );
   if( morph->long_desc )
      DISPOSE( morph->long_desc );
   if( morph->mana )
      DISPOSE( morph->mana );
   if( morph->morph_other )
      DISPOSE( morph->morph_other );
   if( morph->morph_self )
      DISPOSE( morph->morph_self );
   if( morph->move )
      DISPOSE( morph->move );
   if( morph->name )
      DISPOSE( morph->name );
   if( morph->short_desc )
      DISPOSE( morph->short_desc );
   if( morph->skills )
      DISPOSE( morph->skills );
   if( morph->no_skills )
      DISPOSE( morph->no_skills );
   if( morph->unmorph_other )
      DISPOSE( morph->unmorph_other );
   if( morph->unmorph_self )
      DISPOSE( morph->unmorph_self );
   DISPOSE( morph );
   return;
}

below that add
void free_morphs( void )
{
   MORPH_DATA *morph, *morph_next;

   for( morph = morph_start; morph; morph = morph_next )
   {
      morph_next = morph->next;
      unmorph_all( morph );
      UNLINK( morph, morph_start, morph_end, next, prev );
      free_morph( morph );
   }
   return;
}


in act_info.c
find
/*
 * Help editor                                                  -Thoric
 */
void do_hedit( CHAR_DATA * ch, char *argument )

above that add
void free_help( HELP_DATA * pHelp )
{
   UNLINK( pHelp, first_help, last_help, next, prev );
   STRFREE( pHelp->text );
   STRFREE( pHelp->keyword );
   DISPOSE( pHelp );
   return;
}

void free_helps( void )
{
   HELP_DATA *pHelp, *pHelp_next;

   for( pHelp = first_help; pHelp; pHelp = pHelp_next )
   {
      pHelp_next = pHelp->next;
      free_help( pHelp );
   }
   return;
}


in tables.c
find
void save_classes(  )
{
   int x;

   for( x = 0; x < MAX_PC_CLASS; x++ )
      write_class_file( x );
}

below that add
void free_tongues( void )
{
   LANG_DATA *lang, *lang_next;
   LCNV_DATA *lcnv, *lcnv_next;

   for( lang = first_lang; lang; lang = lang_next )
   {
      lang_next = lang->next;

      for( lcnv = lang->first_precnv; lcnv; lcnv = lcnv_next )
      {
         lcnv_next = lcnv->next;
         UNLINK( lcnv, lang->first_precnv, lang->last_precnv, next, prev );
         DISPOSE( lcnv->old );
         DISPOSE( lcnv->lnew );
         DISPOSE( lcnv );
      }
      for( lcnv = lang->first_cnv; lcnv; lcnv = lcnv_next )
      {
         lcnv_next = lcnv->next;
         UNLINK( lcnv, lang->first_cnv, lang->last_cnv, next, prev );
         DISPOSE( lcnv->old );
         DISPOSE( lcnv->lnew );
         DISPOSE( lcnv );
      }
      STRFREE( lang->name );
      STRFREE( lang->alphabet );
      UNLINK( lang, first_lang, last_lang, next, prev );
      DISPOSE( lang );
   }
   return;
}


in skills.c
find
void failed_casting( struct skill_type *skill, CHAR_DATA * ch, CHAR_DATA * victim, OBJ_DATA * obj );

below that add
void free_skill( SKILLTYPE * skill )
{
   SMAUG_AFF *aff, *aff_next;

   if( skill->affects )
   {
      for( aff = skill->affects; aff; aff = aff_next )
      {
         aff_next = aff->next;

         DISPOSE( aff->duration );
         DISPOSE( aff->modifier );
         DISPOSE( aff );
      }
   }
   DISPOSE( skill->name );
   DISPOSE( skill->noun_damage );
   DISPOSE( skill->msg_off );
   DISPOSE( skill->hit_char );
   DISPOSE( skill->hit_vict );
   DISPOSE( skill->hit_room );
   DISPOSE( skill->hit_dest );
   DISPOSE( skill->miss_char );
   DISPOSE( skill->miss_vict );
   DISPOSE( skill->miss_room );
   DISPOSE( skill->die_char );
   DISPOSE( skill->die_vict );
   DISPOSE( skill->die_room );
   DISPOSE( skill->imm_char );
   DISPOSE( skill->imm_vict );
   DISPOSE( skill->imm_room );
   DISPOSE( skill->dice );
   DISPOSE( skill->components );
   DISPOSE( skill->teachers );
   skill->spell_fun = NULL;
   skill->skill_fun = NULL;
   DISPOSE( skill );
   return;
}

void free_skills( void )
{
   SKILLTYPE *skill;
   int hash = 0;

   for( hash = 0; hash < top_sn; hash++ )
   {
      skill = skill_table[hash];
      free_skill( skill );
   }

   for( hash = 0; hash < top_herb; hash++ )
   {
      skill = herb_table[hash];
      free_skill( skill );
   }
   return;
}


in mud_prog.c
find
CHAR_DATA *supermob;
struct act_prog_data *room_act_list;
struct act_prog_data *obj_act_list;
struct act_prog_data *mob_act_list;

below that add this
void free_prog_actlists( void )
{
   struct act_prog_data *apd, *apd_next;

   for( apd = room_act_list; apd; apd = apd_next )
   {
      apd_next = apd->next;
      DISPOSE( apd );
   }

   for( apd = obj_act_list; apd; apd = apd_next )
   {
      apd_next = apd->next;
      DISPOSE( apd );
   }

   for( apd = mob_act_list; apd; apd = apd_next )
   {
      apd_next = apd->next;
      DISPOSE( apd );
   }
   return;
}


in act_wiz.c
find
void close_area( AREA_DATA * pArea )

after that function add this
void close_all_areas( void )
{
   AREA_DATA *area, *area_next;

   for( area = first_area; area; area = area_next )
   {
      area_next = area->next;
      close_area( area );
   }
   return;
}

find
WATCH_DATA *first_watch;
WATCH_DATA *last_watch;

below that add
void free_watchlist( void )
{
   WATCH_DATA *pw, *pw_next;

   for( pw = first_watch; pw; pw = pw_next )
   {
      pw_next = pw->next;
      UNLINK( pw, first_watch, last_watch, next, prev );
      DISPOSE( pw->imm_name );
      DISPOSE( pw->player_site );
      DISPOSE( pw->target_name );
      DISPOSE( pw );
   }
   return;
}

find
void free_social( SOCIALTYPE * social )
{
   if( social->name )
      DISPOSE( social->name );
   if( social->char_no_arg )
      DISPOSE( social->char_no_arg );
   if( social->others_no_arg )
      DISPOSE( social->others_no_arg );
   if( social->char_found )
      DISPOSE( social->char_found );
   if( social->others_found )
      DISPOSE( social->others_found );
   if( social->vict_found )
      DISPOSE( social->vict_found );
   if( social->char_auto )
      DISPOSE( social->char_auto );
   if( social->others_auto )
      DISPOSE( social->others_auto );
   DISPOSE( social );
}

below that add
void free_socials( void )
{
   SOCIALTYPE *social, *social_next;
   int hash;

   for( hash = 0; hash < 27; hash++ )
   {
      for( social = social_index[hash]; social; social = social_next )
      {
         social_next = social->next;
         free_social( social );
      }
   }
   return;
}

find
void free_command( CMDTYPE * command )
{
   if( command->name )
      DISPOSE( command->name );
   DISPOSE( command );
}

below that add
void free_commands( void )
{
   CMDTYPE *command, *cmd_next;
   int hash;

   for( hash = 0; hash < 126; hash++ )
   {
      for( command = command_hash[hash]; command; command = cmd_next )
      {
         cmd_next = command->next;
         command->next = NULL;
         command->do_fun = NULL;
         free_command( command );
      }
   }
   return;
}

in deity.c
find
DEITY_DATA *get_deity( char *name )
{
   DEITY_DATA *deity;
   for( deity = first_deity; deity; deity = deity->next )
      if( !str_cmp( name, deity->name ) )
         return deity;
   return NULL;
}

above that add
void free_deity( DEITY_DATA * deity )
{
   UNLINK( deity, first_deity, last_deity, next, prev );
   STRFREE( deity->name );
   DISPOSE( deity->description );
   DISPOSE( deity->filename );
   DISPOSE( deity );
   return;
}

void free_deities( void )
{
   DEITY_DATA *deity, *deity_next;

   for( deity = first_deity; deity; deity = deity_next )
   {
      deity_next = deity->next;
      free_deity( deity );
   }
   return;
}

in clans.c
find
CLAN_DATA *get_clan( char *name )
{
   CLAN_DATA *clan;

   for( clan = first_clan; clan; clan = clan->next )
      if( !str_cmp( name, clan->name ) )
         return clan;
   return NULL;
}

above that add
void free_one_clan( CLAN_DATA * clan )
{
   UNLINK( clan, first_clan, last_clan, next, prev );
   DISPOSE( clan->filename );
   STRFREE( clan->name );
   STRFREE( clan->motto );
   STRFREE( clan->description );
   STRFREE( clan->deity );
   STRFREE( clan->leader );
   STRFREE( clan->number1 );
   STRFREE( clan->number2 );
   STRFREE( clan->leadrank );
   STRFREE( clan->onerank );
   STRFREE( clan->tworank );
   STRFREE( clan->badge );
   DISPOSE( clan );
   return;
}

void free_clans( void )
{
   CLAN_DATA *clan, *clan_next;

   for( clan = first_clan; clan; clan = clan_next )
   {
      clan_next = clan->next;
      free_one_clan( clan );
   }
   return;
}

Post is unread #2 Aug 20, 2005 7:06 pm   
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,946
JoinedJul 26, 2005

 
Oh, for those who don't know having your mud cleanup_memory on exit helps out when you toss your mud into valgrind to check for leaks and all. Most of this came from afkmud and was just modified (where it needed to be) to fit into smaugfuss.

Hope someone finds it useful.

Post is unread #3 Aug 20, 2005 9:52 pm   
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,696
JoinedJan 1, 2002

 
Also keep in mind that this addition has been made to the SmaugFUSS distribution as of 8/20/05 but is not being posted to the fix list since it is not technically a bug, but is indeed a useful feature to have when debugging is needed.

Post is unread #4 Aug 20, 2005 11:15 pm   
Go to the top of the page
Go to the bottom of the page

Gatz
Apprentice
GroupMembers
Posts60
JoinedJul 25, 2005

 
I'll come out and say it: God Bless you Remcon. I've been pining over porting the AFKMUD one for awhile now but it just seemed like a tedious prospect. Thank you for doing this.

Post is unread #5 Aug 20, 2005 11:22 pm   
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,946
JoinedJul 26, 2005

 
You're welcome, it seemed like it was past due for it to be done and I was kind of annoyed at what I was working on and fiqured I would take the time to do so, for the smaugfuss download. Orginaly wasnt going to do it into a snippet or anything until someone asked me if they had to update to the newest release to get the addition and well fiqured then i would go ahead and make a snippet out of the changes for everyone :) Glad someone is finding it useful :)

Post is unread #6 Aug 21, 2005 1:27 am   
Go to the top of the page
Go to the bottom of the page

Gatz
Apprentice
GroupMembers
Posts60
JoinedJul 25, 2005

 
I did notice some minor issues for example when it frees the skills it assumes all part of a skill is used when my code (SMAUG FUSS 1.5) that isn't true. So I had some minor issues cleaning up error messages. However, I've Valgrinded a few times and pulled up two new things I've never seen before. I was going to post it in a seperate topic however since it appeared after I installed this code I figured I'd post it here to see if it really caught something or I just botched something.

==25290== 32 bytes in 2 blocks are definitely lost in loss record 1 of 13
==25290==    at 0x1B9046C5: calloc (vg_replace_malloc.c:176)
==25290==    by 0x80AA405: load_rooms (db.c:2314)
==25290==    by 0x80B2174: load_area_file (db.c:6092)
==25290==    by 0x80A7B07: boot_db (db.c:731)
==25290==    by 0x809F59E: main (comm.c:547)
==25290==
==25290==
==25290== 712 bytes in 1 blocks are definitely lost in loss record 7 of 13
==25290==    at 0x1B9046C5: calloc (vg_replace_malloc.c:176)
==25290==    by 0x8105CF2: load_char_obj (save.c:894)
==25290==    by 0x80A1355: nanny (comm.c:1879)
==25290==    by 0x809FD48: game_loop (comm.c:922)
==25290==    by 0x809F66E: main (comm.c:576)


            else if ( letter == 'M' )    /* maps */
            {
                MAP_DATA *map;
                MAP_INDEX_DATA *map_index;
                int i, j;

                CREATE( map, MAP_DATA, 1);
                map->vnum                     = fread_number( fp );
                map->x                        = fread_number( fp );
                map->y                        = fread_number( fp );
                map->entry                    = fread_letter( fp );

                pRoomIndex->map               = map;
                if(  (map_index = get_map_index(map->vnum)) == NULL  )
                {
                     CREATE( map_index, MAP_INDEX_DATA, 1);
                     map_index->vnum = map->vnum;
                     map_index->next = first_map;
                     first_map       = map_index;
                     for (i = 0; i <  49; i++) {
                             for (j = 0; j <  79; j++) {
                               map_index->map_of_vnums[i][j] = -1;
                               /* map_index->map_of_ptrs[i][j] = NULL; */
                             }
                     }

                }
                if( (map->y <0) || (map->y >48) )
                {
                    bug("Map y coord out of range.  Room %d\n\r", map->y);

                }
                if( (map->x <0) || (map->x >78) )
                {
                    bug("Map x coord out of range.  Room %d\n\r", map->x);

                }
                if(  (map->x >0)
                   &&(map->x <80)
                   &&(map->y >0)
                   &&(map->y <48) )
                   map_index->map_of_vnums[map->y][map->x]=pRoomIndex->vnum;
            }


bool load_char_obj( DESCRIPTOR_DATA *d, char *name, bool preload, bool copyover )
{
    char strsave[MAX_INPUT_LENGTH];
    CHAR_DATA *ch;
    FILE *fp;
    bool found;
    struct stat fst;
    int i, x;
    extern FILE *fpArea;
    extern char strArea[MAX_INPUT_LENGTH];
    char buf[MAX_INPUT_LENGTH];

    CREATE( ch, CHAR_DATA, 1 ); <-----****

I didn't post all of load_char_obj because it was too big and would be pointless. I tried a few fixes and...fell flat.

Post is unread #7 Aug 21, 2005 9:31 am   
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,696
JoinedJan 1, 2002

 
The one for mapout is easily fixed. There was a fix posted about that one a few days back. The old stock system for that simply didn't work and Remcon replaced it with one that does and it doesn't have all the junk in the section of code you posted.

Not sure why load_char_obj is being triggered. There should be a call in cleanup_memory to free all chars, and if there's not, then it needs to be added. That should have taken care of this.

Post is unread #8 Aug 21, 2005 10:45 am   Last edited Aug 21, 2005 10:53 am by Remcon
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,946
JoinedJul 26, 2005

 
If you want to keep the old mapout system have to add in for it to free up the map data and well to be honest i dont have a copy of the old system to be of any help on what you should add to free it :)
You can try adding this to cleanup_memory
  {
      MAP_INDEX_DATA *map, *map_next;

      for(map = first_map; map; map = map_next)
      {
         map_next = map->next;
         /* Unlink might work for this if not you will have to manually handle it */
         UNLINK(map, first_map, last_map, next, prev);
         DISPOSE(map);
      }
  }

as for this one
==25290== 712 bytes in 1 blocks are definitely lost in loss record 7 of 13
==25290==    at 0x1B9046C5: calloc (vg_replace_malloc.c:176)
==25290==    by 0x8105CF2: load_char_obj (save.c:894)
==25290==    by 0x80A1355: nanny (comm.c:1879)
==25290==    by 0x809FD48: game_loop (comm.c:922)
==25290==    by 0x809F66E: main (comm.c:576)

It looks like there is at least one character it didnt free which could mean there is some issue in it adding/removing characters and you will have to do some checking to find out for sure. When I added this it was done on the latest SmaugFUSS at the time earlier versions of the code might need a few things added. Once you get them fiqured out feel free to post it as well as what version needs it so others will be able to use it if you have time :)

Post is unread #9 Aug 21, 2005 1:57 pm   Last edited Aug 21, 2005 2:21 pm by Gatz
Go to the top of the page
Go to the bottom of the page

Gatz
Apprentice
GroupMembers
Posts60
JoinedJul 25, 2005

 
Thanks for the help, any chance something like this can be ported to SWR FUSS? I'm sure it wouldn't be much more work to add in planets and ships.

Post is unread #10 Aug 21, 2005 2:38 pm   
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,946
JoinedJul 26, 2005

 
yea it could probably get ported to that also :) feel free to do it and post it if you want :) heh If no one else has gotten to it and I get time sometime I'll do it, but shrug just depends on when I have time :)

Post is unread #11 Aug 21, 2005 11:01 pm   
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,946
JoinedJul 26, 2005

 
Ok, looks like found something else its not freeing so going to go ahead and put how to fix that
in planes.c at the end of the file
add
void free_plane( PLANE_DATA *p )
{
   if( !p )
      return;
   UNLINK( p, first_plane, last_plane, next, prev );
   STRFREE( p->name );
   DISPOSE( p );
return;
}

void free_all_planes( void )
{
   PLANE_DATA *p, *p_next;

   for( p = first_plane; p; p = p_next )
   {
      p_next = p->next;
      free_plane( p );
   }
return;
}

in comm.c
find
void free_projects( void );
void free_bans( void );
void free_clans( void );
void free_morphs( void );
void free_deities( void );

after that add
void free_all_planes( void );

find
   /*
    * Areas - this includes killing off the hash tables and such
    */
   fprintf( stdout, "%s", "Area Data Tables.\n" );
   close_all_areas(  );

after that add
   /*
    * Planes
    */
   fprintf( stdout, "%s", "Planes.\n" );
   free_all_planes(  );

This will get it to free plane data :)

Post is unread #12 Aug 21, 2005 11:03 pm   
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,946
JoinedJul 26, 2005

 
Now this one is a little more tricky and not only covers something left out of cleanup_memory but also covers a bug in smaugfuss :)
in mud.h
find
#define AFLAG_NOPKILL               BV00
#define AFLAG_FREEKILL              BV01
#define AFLAG_NOTELEPORT            BV02
#define AFLAG_SPELLLIMIT            BV03

below that add
#define AFLAG_PROTOTYPE             BV04 /* Used to keep memory cleaned correctly */


in build.c
find
char *const area_flags[] = {
   "nopkill", "freekill", "noteleport", "spelllimit", "r4", "r5", "r6", "r7", "r8",
   "r9", "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17",
   "r18", "r19", "r20", "r21", "r22", "r23", "r24",
   "r25", "r26", "r27", "r28", "r29", "r30", "r31"
};

change it to this so it cant be set on the game
*its just changing the "r4" to ""
char *const area_flags[] = {
   "nopkill", "freekill", "noteleport", "spelllimit", "", "r5", "r6", "r7", "r8",
   "r9", "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17",
   "r18", "r19", "r20", "r21", "r22", "r23", "r24",
   "r25", "r26", "r27", "r28", "r29", "r30", "r31"
};

in act_wiz.c find
/* If you dont have the first_area_name one it was a fix i posted earlier */
   UNLINK( pArea, first_area, last_area, next, prev );
   UNLINK( pArea, first_build, last_build, next, prev );
   UNLINK( pArea, first_asort, last_asort, next_sort, prev_sort );
   UNLINK( pArea, first_bsort, last_bsort, next_sort, prev_sort );
   UNLINK( pArea, first_area_name, last_area_name, next_sort_name, prev_sort_name );
   DISPOSE( pArea );

change it to this
   if( IS_SET( pArea->flags, AFLAG_PROTOTYPE ))
   {
      UNLINK( pArea, first_build, last_build, next, prev );
      UNLINK( pArea, first_bsort, last_bsort, next_sort, prev_sort );
   }
   else
   {
      UNLINK( pArea, first_area, last_area, next, prev );
      UNLINK( pArea, first_asort, last_asort, next_sort, prev_sort );
      UNLINK( pArea, first_area_name, last_area_name, next_sort_name, prev_sort_name );
   }
   DISPOSE( pArea );

Also if you have added close_all_areas for cleanup_memory
change
void close_all_areas( void )
{
   AREA_DATA *area, *area_next;

   for( area = first_area; area; area = area_next )
   {
      area_next = area->next;
      close_area( area );
   }
   return;
}

to this
void close_all_areas( void )
{
   AREA_DATA *area, *area_next;

   for( area = first_area; area; area = area_next )
   {
      area_next = area->next;
      close_area( area );
   }
   for( area = first_build; area; area = area_next )
   {
      area_next = area->next;
      close_area( area );
   }
   return;
}

in db.c load_buildlist
find
            LINK( pArea, first_build, last_build, next, prev );
            fprintf( stderr, "%-14s: Rooms: %5d - %-5d Objs: %5d - %-5d "
                     "Mobs: %5d - %-5d\n",
                     pArea->filename,
                     pArea->low_r_vnum, pArea->hi_r_vnum,
                     pArea->low_o_vnum, pArea->hi_o_vnum, pArea->low_m_vnum, pArea->hi_m_vnum );
            sort_area( pArea, TRUE );

above the link add this
            SET_BIT( pArea->flags, AFLAG_PROTOTYPE );

in build.c fold_area
find
   fprintf( fpout, "#AREA   %s~\n\n\n\n", tarea->name );
   fprintf( fpout, "#VERSION %d\n", AREA_VERSION_WRITE );
   fprintf( fpout, "#AUTHOR %s~\n\n", tarea->author );
   fprintf( fpout, "#RANGES\n" );
   fprintf( fpout, "%d %d %d %d\n", tarea->low_soft_range,
            tarea->hi_soft_range, tarea->low_hard_range, tarea->hi_hard_range );

above that add
   if( install )
     REMOVE_BIT( tarea->flags, AFLAG_PROTOTYPE );


Found that building data wasnt being freed and when trying to free it found that how it handled the list was making the data bad in them this corrects both issues and will help out in looking for memory leaks enjoy.

Post is unread #13 Aug 22, 2005 8:42 pm   
Go to the top of the page
Go to the bottom of the page

Conner
Sorcerer
GroupMembers
Posts870
JoinedMay 8, 2005

 
Ok, like this thread isn't long enough yet.. I found two little compiler warnings in comm.c out of this mess, and two little compiler errors in tables.c, let me just point out that if you don't have I3 installed, the warning doesn't matter, and the error is really minor, one character...

in tables.c
just change the 2 lines from
DISPOSE( lcnv->lnew );
to
DISPOSE( lcnv->new );


in comm.c
after the
void free_all_planes( void );

insert
#ifdef I3

void destroy_I3_mud( I3_MUD * mud );

void free_i3data( bool freerouters );

#endif

and it should compile nice and clean. I have verified this with Remcon, but he wanted me to post it because I found it. (Once again, thanks Remcon!)

Post is unread #14 Aug 22, 2005 9:51 pm   
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,946
JoinedJul 26, 2005

 
The i3 thing is good
this part
in tables.c
just change the 2 lines from
DISPOSE( lcnv->lnew );
to
DISPOSE( lcnv->new );

Thats if you have a version of SmaugFUSS prior to 1.6 (not sure when it exactly got changed to lnew there lol) :)

Post is unread #15 Aug 22, 2005 9:57 pm   
Go to the top of the page
Go to the bottom of the page

Conner
Sorcerer
GroupMembers
Posts870
JoinedMay 8, 2005

 
hmm, and I thought I'd kept up with all Samson's changes and posted bug fixes... *shrug*

Post is unread #16 Aug 25, 2005 8:22 am   
Go to the top of the page
Go to the bottom of the page

Zeno
Sorcerer
GroupMembers
Posts723
JoinedMar 5, 2005

 
Have an issue with cleanup_memory.
Thu Aug 25 06:00:00 2005 :: Automatic Reboot
Thu Aug 25 06:00:00 2005 :: Shutting down Wolfpaw webserver on port 1803.
Thu Aug 25 06:00:00 2005 :: Normal termination of game.
Thu Aug 25 06:00:00 2005 :: Cleaning up Memory.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RDISPOSE called on STRALLOC pointer: boards.c, line 53

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RDISPOSE called on STRALLOC pointer: boards.c, line 56

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RDISPOSE called on STRALLOC pointer: boards.c, line 53

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RDISPOSE called on STRALLOC pointer: boards.c, line 56

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RSTRFREE called on str_dup pointer: boards.c, line 52

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RDISPOSE called on STRALLOC pointer: boards.c, line 53

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RDISPOSE called on STRALLOC pointer: boards.c, line 56

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RDISPOSE called on STRALLOC pointer: boards.c, line 53

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RDISPOSE called on STRALLOC pointer: boards.c, line 56

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RSTRFREE called on str_dup pointer: boards.c, line 52

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RDISPOSE called on STRALLOC pointer: boards.c, line 53

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RDISPOSE called on STRALLOC pointer: boards.c, line 56

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RDISPOSE called on STRALLOC pointer: boards.c, line 53

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RDISPOSE called on STRALLOC pointer: boards.c, line 56

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RDISPOSE called on STRALLOC pointer: boards.c, line 53

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
Thu Aug 25 06:00:00 2005 :: [*****] BUG: &RDISPOSE called on STRALLOC pointer: boards.c, line 56

Thu Aug 25 06:00:00 2005 :: Attempting to correct.
*** glibc detected *** inuyasha: free(): invalid pointer: 0x0817a54d ***
======= Backtrace: =========
/lib/libc.so.6[0x31f124]
/lib/libc.so.6(__libc_free+0x77)[0x31f65f]
inuyasha[0x80b9faf]
inuyasha[0x80bab73]
/lib/libc.so.6(__libc_start_main+0xdf)[0x2d0d5f]
inuyasha[0x804990d]
======= Memory map: ========
002bc000-003df000 r-xp 00000000 03:03 32214      /lib/libc-2.3.5.so.#prelink#.m3mgDa (deleted)
003df000-003e1000 r-xp 00123000 03:03 32214      /lib/libc-2.3.5.so.#prelink#.m3mgDa (deleted)
003e1000-003e3000 rwxp 00125000 03:03 32214      /lib/libc-2.3.5.so.#prelink#.m3mgDa (deleted)
003e3000-003e5000 rwxp 003e3000 00:00 0
00661000-00666000 r-xp 00000000 03:03 32246      /lib/libcrypt-2.3.5.so.#prelink#.grbQnd (deleted)
00666000-00667000 r-xp 00004000 03:03 32246      /lib/libcrypt-2.3.5.so.#prelink#.grbQnd (deleted)

00666000-00667000 r-xp 00004000 03:03 32246      /lib/libcrypt-2.3.5.so.#prelink#.grbQnd (deleted)
00667000-00668000 rwxp 00005000 03:03 32246      /lib/libcrypt-2.3.5.so.#prelink#.grbQnd (deleted)
00668000-0068f000 rwxp 00668000 00:00 0
006a6000-006c0000 r-xp 00000000 03:03 32332      /lib/ld-2.3.5.so.#prelink#.n9Lmja (deleted)
006c0000-006c1000 r-xp 00019000 03:03 32332      /lib/ld-2.3.5.so.#prelink#.n9Lmja (deleted)
006c1000-006c2000 rwxp 0001a000 03:03 32332      /lib/ld-2.3.5.so.#prelink#.n9Lmja (deleted)
00a3a000-00a4c000 r-xp 00000000 03:05 20815      /usr/lib/libz.so.1.2.2.2.#prelink#.uB36rW (deleted)
00a4c000-00a4d000 rwxp 00011000 03:05 20815      /usr/lib/libz.so.1.2.2.2.#prelink#.uB36rW (deleted)
00b15000-00b24000 r-xp 00000000 03:03 34022      /lib/libresolv-2.3.5.so
00b24000-00b25000 r-xp 0000e000 03:03 34022      /lib/libresolv-2.3.5.so
00b25000-00b26000 rwxp 0000f000 03:03 34022      /lib/libresolv-2.3.5.so
00b26000-00b28000 rwxp 00b26000 00:00 0
00b2a000-00b33000 r-xp 00000000 03:03 32520      /lib/libgcc_s-4.0.1-20050727.so.1
00b33000-00b34000 rwxp 00009000 03:03 32520      /lib/libgcc_s-4.0.1-20050727.so.1
00ec8000-00ec9000 r-xp 00ec8000 00:00 0
00eda000-00ee3000 r-xp 00000000 03:03 32284      /lib/libnss_files-2.3.5.so
00ee3000-00ee4000 r-xp 00008000 03:03 32284      /lib/libnss_files-2.3.5.so
00ee4000-00ee5000 rwxp 00009000 03:03 32284      /lib/libnss_files-2.3.5.so
00f36000-00f3a000 r-xp 00000000 03:03 32280      /lib/libnss_dns-2.3.5.so
00f3a000-00f3b000 r-xp 00003000 03:03 32280      /lib/libnss_dns-2.3.5.so
00f3b000-00f3c000 rwxp 00004000 03:03 32280      /lib/libnss_dns-2.3.5.so
08048000-081d5000 r-xp 00000000 03:07 13915309   /home/iyg/mud/src/inuyasha
081d5000-081d6000 rw-p 0018c000 03:07 13915309   /home/iyg/mud/src/inuyasha
081d6000-08203000 rw-p 081d6000 00:00 0
09562000-09933000 rw-p 09562000 00:00 0          [heap]
b7e00000-b7e21000 rw-p b7e00000 00:00 0
b7e21000-b7f00000 ---p b7e21000 00:00 0
b7f61000-b7f62000 rw-p b7f61000 00:00 0
b7f62000-b7f97000 r--s 00000000 03:06 48351      /var/db/nscd/hosts
b7f97000-b7f99000 rw-p b7f97000 00:00 0
bfc8d000-bfca2000 rw-p bfc8d000 00:00 0          [stack]
Project Data.
Ban Data.
Morph Data.
Commands.
Clans.
Socials.
Watches.

Helps.
Boards.
Whacking supermob.
Objects.
Characters.
Descriptors.
Races.


And it just crashes.

Post is unread #17 Aug 25, 2005 9:39 am   Last edited Aug 25, 2005 1:04 pm by Remcon
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,946
JoinedJul 26, 2005

 
The problem is that in C you can't make sure its a (char *) before trying to check the hash table for it.

For your problem though check and see how you have it allocating the memory to the things its complaining about. Naturally if you are using STRALLOC/fread_string use STRFREE and if you are using str_dup/fread_string_nohash use DISPOSE. If it complains and all those are set right I would just remove the checks in mud.h for it to check the hash for strings from STRFREE and DISPOSE. I found it causing crashes on creation of cleanup_memory because DISPOSE will try to send it to be checked when its not even a (char *) which will cause a crash.

Post is unread #18 Aug 25, 2005 4:21 pm   
Go to the top of the page
Go to the bottom of the page

Zeno
Sorcerer
GroupMembers
Posts723
JoinedMar 5, 2005

 
Yeah, I know that because of the bugs. I just didn't think it'd make the MUD crash. When I get the chance to fix it, I'll let you know if its fine.

Post is unread #19 Aug 26, 2005 7:17 am   
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,696
JoinedJan 1, 2002

 

in tables.c
just change the 2 lines from
DISPOSE( lcnv->lnew );
to
DISPOSE( lcnv->new );



This isn't actually a bug and should be getting cleaned up properly. It was changed to lnew because the code for SmaugFUSS has been run through g++ on a few occasions to see how well it would hold up and using ->new causes a compile failure for a reserved keyword.

The only reason to fix this particular issue is if your code was not branched from one of the FUSS packages that has this change.

Post is unread #20 Aug 26, 2005 5:58 pm   
Go to the top of the page
Go to the bottom of the page

Conner
Sorcerer
GroupMembers
Posts870
JoinedMay 8, 2005

 
in boards.c
DISPOSE( project->description );

should be
STRFREE( project->description );

and before
UNLINK( project, first_project, last_project, next, prev );

you need to add
STRFREE( project->date );

Pages:<< prev 1, 2 next >>