Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
AFKMud 2.2.2
Mar 3, 2019 5:35 pm
By Samson
Development
Nov 28, 2018 12:10 pm
By Keirath
First Immortal
Oct 12, 2018 2:02 pm
By GatewaySysop
Bug in do_climb( )
Jun 5, 2018 7:31 pm
By joeyfogas
question on overland code
May 31, 2018 12:03 pm
By joeyfogas
SmaugFUSS 1.9.3
Author: Various
Submitted by: Samson
AFKMud 2.2.2
Author: AFKMud Team
Submitted by: Samson
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
Users Online
CommonCrawl, Bing

Members: 0
Guests: 20
Stats
Files
Topics
Posts
Members
Newest Member
483
3,743
19,401
655
RodrickMci
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds » Bugfix Lists » SWR FUSS Bugfix List » [Bug] show_file function has ...
Forum Rules | Mark all | Recent Posts

[Bug] show_file function has a descriptor leak
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Mar 5, 2005 9:42 pm   Last edited May 6, 2005 2:11 am by Samson
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,647
JoinedJan 1, 2002

Bug: show_file function has a descriptor leak.
Danger: High - Resource drain
Found by: Greven
Fixed by: Greven

---

db.c, show_file

The function should look as follows:

void show_file( CHAR_DATA * ch, char *filename )
{
   FILE *fp;
   char buf[MAX_STRING_LENGTH];
   int c;
   int num = 0;

   if( ( fp = fopen( filename, "r" ) ) != NULL )
   {
      while( !feof( fp ) )
      {
         while( ( buf[num] = fgetc( fp ) ) != EOF
                && buf[num] != '\n' && buf[num] != '\r' && num < ( MAX_STRING_LENGTH - 2 ) )
            num++;
         c = fgetc( fp );
         if( ( c != '\n' && c != '\r' ) || c == buf[num] )
            ungetc( c, fp );
         buf[num++] = '\n';
         buf[num++] = '\r';
         buf[num] = '\0';
         send_to_pager( buf, ch );
         num = 0;
      }
      fclose( fp );
   }
}


The function is missing the fclose statement near the bottom in the unmodified source. Files which are left open are not usually an overly large problem, but with show_file this could quickly get to be a serious drain since this function is used in a few places to display files to users while the MUD is running.
       
Pages:<< prev 1 next >>