Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
auth_update crash
Dec 23, 2017, 10:15 pm
By Remcon
check_tumble
Dec 18, 2017, 7:21 pm
By Remcon
parse description bug
Dec 15, 2017, 10:08 pm
By Remcon
Couple bugs
Dec 12, 2017, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Bing, Yahoo!, Yandex

Members: 0
Guests: 10
Stats
Files
Topics
Posts
Members
Newest Member
478
3,708
19,242
612
Jacki72H
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SmaugFUSS » memory leak in fread_morph
Forum Rules | Mark all | Recent Posts

memory leak in fread_morph
< Newer Topic :: Older Topic > blasted leaks

Pages:<< prev 1 next >>
Post is unread #1 Aug 21, 2005, 11:39 am   Last edited Aug 21, 2005, 11:40 am by Remcon
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,868
JoinedJul 26, 2005

Ok, found that if you have morphs you have a memory leak if you have morph->race or morph->class here is the best way to fix it, but if you have a better way feel free.
in db.c
find
/*
 * Read a string from file fp
 */
char *fread_string( FILE * fp )
{

above it add
/* Read a string from file and return it */
char *fread_flagstring(FILE *fp)
{
  static char flagstring[MAX_STRING_LENGTH];
  char *plast;
  char c;
  int ln;

  plast = flagstring;
  flagstring[0] = '\0';
  ln = 0;
  /* Skip blanks. Read first char. */
  do
  {
    if(feof(fp))
    {
      bug("%s", "fread_flagstring: EOF encountered on read.\n\r";);
      if(fBootDb)
        exit(1);
      return "";
    }
    c = getc(fp);
  }
  while(isspace(c));
  if((*plast++ = c) == '~')
    return "";
  for(;;)
  {
    if(ln >= (MAX_STRING_LENGTH - 1))
    {
      bug("%s", "fread_flagstring: string too long";);
      *plast = '\0';
    return flagstring;
    }
    switch(*plast = getc(fp))
    {
      default:
        plast++;
        ln++;
      break;
      case EOF:
        bug("%s", "Fread_flagstring: EOF";);
        if(fBootDb)
          exit(1);
        *plast = '\0';
        return flagstring;
      break;
      case '\n':
        plast++;
        ln++;
        *plast++ = '\r';  ln++;
      break;
      case '\r':
      break;
      case '~':
        *plast = '\0';
      return flagstring;
    }
  }
}


In mud.h
find
char *fread_string args( ( FILE * fp ) );
char *fread_string_nohash args( ( FILE * fp ) );

and below those add
char *fread_flagstring args( ( FILE * fp ) );


Now lets fix the two memory leaks this is designed to fix :)
in polymorph.c in fread_morph
find
            if( !str_cmp( word, "Class" ) )
            {
               arg = fread_string( fp );
               while( arg[0] != '\0' )
               {
                  arg = one_argument( arg, temp );
                  for( i = 0; i < MAX_PC_CLASS; i++ )
                     if( !str_cmp( temp, class_table[i]->who_name ) )
                     {
                        SET_BIT( morph->Class, ( 1 << i ) );
                        break;
                     }
               }
               fMatch = TRUE;
               break;
            }

change that to
            if( !str_cmp( word, "Class" ) )
            {
               arg = fread_flagstring( fp );
               while( arg[0] != '\0' )
               {
                  arg = one_argument( arg, temp );
                  for( i = 0; i < MAX_PC_CLASS; i++ )
                     if( !str_cmp( temp, class_table[i]->who_name ) )
                     {
                        SET_BIT( morph->Class, ( 1 << i ) );
                        break;
                     }
               }
               fMatch = TRUE;
               break;
            }

then find
            if( !str_cmp( word, "Race" ) )
            {
               arg = fread_string_nohash( fp );
               arg = one_argument( arg, temp );
               while( temp[0] != '\0' )
               {
                  for( i = 0; i < MAX_PC_RACE; i++ )
                     if( !str_cmp( temp, race_table[i]->race_name ) )
                     {
                        SET_BIT( morph->race, ( 1 << i ) );
                        break;
                     }
                  arg = one_argument( arg, temp );
               }
               fMatch = TRUE;
               break;
            }

and change it to
            if( !str_cmp( word, "Race" ) )
            {
               arg = fread_flagstring( fp );
               while( arg[0] != '\0' )
               {
                  arg = one_argument( arg, temp );
                  for( i = 0; i < MAX_PC_RACE; i++ )
                     if( !str_cmp( temp, race_table[i]->race_name ) )
                     {
                        SET_BIT( morph->race, ( 1 << i ) );
                        break;
                     }
               }
               fMatch = TRUE;
               break;
            }

Hope this helps someone out :)
       
Post is unread #2 Aug 21, 2005, 11:46 am
Go to the top of the page
Go to the bottom of the page

Remcon
Geomancer
GroupAdministrators
Posts1,868
JoinedJul 26, 2005

Btw if memory serves this was found long ago and is a reason fread_flagstring was created, couldnt tell you who it was though that orginaly found it (it was like quite along time ago when it was orginaly found)
       
Pages:<< prev 1 next >>