--- [EMAIL PROTECTED] wrote:
> Ok.. I have a function that seems to have (definately has) a memory leak.
[SNIP]
> void do_plist( CHAR_DATA *ch, char *argument )
> {
> DIR *dp;
> FILE *fp;
> CHAR_DATA *victim = NULL;
> struct dirent *ep;
> char buf[80];
> char buf2[MSL];
> char buf3[MSL];
> char buffer[MAX_STRING_LENGTH*4];
> bool fOld;
> char arg1 [MAX_INPUT_LENGTH];
> char arg2 [MAX_INPUT_LENGTH];
> int days;
> int type = 0;
> int clan = -1;
> int god = -1;
> int race = -1;
[SNIP]
>
> dp = opendir ("../player");
>
> if (dp != NULL)
> {
> while ( (ep = readdir (dp)) )
> {
> if ( ep->d_name[0] == '.' )
> continue;
>
/* Allocated new character_data, and new pc_data here */
> victim = new_char();
> victim->pcdata = new_pcdata();
> fOld = FALSE;
>
> sprintf( buf2, "%s%s", PLAYER_DIR, capitalize( ep->d_name ) );
> if ( ( fp = fopen( buf2, "r" ) ) != NULL )
> {
> int iNest;
>
> for ( iNest = 0; iNest < MAX_NEST; iNest++ )
> rgObjNest[iNest] = NULL;
>
> fOld = TRUE;
>
> for ( ; ; )
> {
> char letter;
> char *word;
>
> letter = fread_letter( fp );
> if ( letter == '*' )
> {
> fread_to_eol( fp );
> continue;
> }
>
> if ( letter != '#' )
> {
> bug( "Load_char_obj: # not found.", 0 );
> break;
> }
>
> word = fread_word( fp );
> if ( !str_cmp( word, "PLAYER" ) ) fread_char( victim, fp );
> else if ( !str_cmp( word, "OBJECT" ) ) break;
> else if ( !str_cmp( word, "O" ) ) break;
> else if ( !str_cmp( word, "PET" ) ) break;
> else if ( !str_cmp( word, "END" ) ) break;
> else
> {
> bug( "Load_char_obj: bad section.", 0 );
> break;
> }
> }
> fclose( fp );
> }
/* If fOld is false, we didn't free the character we allocated...... BAD */
>
> if (!fOld)
> continue;
>
> if (type == 1 && (victim->clan != clan || IS_IMMORTAL(victim)))
> continue;
>
> if (type == 2 && (victim->god != god || IS_IMMORTAL(victim)))
> continue;
>
> if (type == 3 && (victim->race != race || IS_IMMORTAL(victim)))
> continue;
>
> if (type == 4 && (victim->tier > 1 || IS_IMMORTAL(victim)))
> continue;
>
> if (type == 5 && (victim->tier != 2 || IS_IMMORTAL(victim)))
> continue;
>
> if (type == 6 && (!IS_IMMORTAL(victim) || victim->level >
> ch->level))
> continue;
/* If any of the above checks succeed, we skip without freeing the character
we allocated.... BAD
*/
> sprintf( buf, "%s%s", "../player/", ep->d_name );
>
> days = days_since_last_file_mod( buf );
>
> sprintf( buf, "%-15s %s%-3d{x days\n\r",
> ep->d_name, days >= 30 ? "{r" : days >= 15 ? "{Y" : days >=
> 10 ? "{g" : "{G", days);
> strcat( buffer, buf );
> }
> closedir (dp);
> free_pcdata(victim->pcdata);
> free_char(victim);
> }
> else
> perror ("Couldn't open the directory");
>
> page_to_char( buffer, ch );
/* Here we're freeing a bunch of variables we didn't allocate, so
most likely we've trashed our stack... BAD
*/
> free_string(buffer);
> free_string(buf);
> free_string(buf2);
> free_string(buf3);
> return;
> }
Hope that helps,
~Kender
=====
-----BEGIN GEEK CODE BLOCK-----
Version 3.1
GCS/L/C/O d-(+) s++: a-- C+++$>++++ UBLS++++$
P+++(--)$ L+++>++++ E--- W+>++$ N !o K? w(--) !O
M- !V PS+ PE(++) Y+ PGP->+ t+ 5 X+() R(+) tv+@
b++(+++) !DI+++ D G(-) e>+++$ h---() r+++ y+++
------END GEEK CODE BLOCK------
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com