#8 file descriptor leak in ConfigFile.c

open
nobody
None
5
2006-05-12
2006-05-12
Anonymous
No

Note this code from ConfigFile_Parse() in ConfigFile.c:

if((fp = fopen(filename, "r")) == NULL)
{
FatalError("Failed to open config file '%s':
%s\n", filename,
strerror(errno));
goto error;
}

file_name = filename;
file_line = 0;

if((fp = fopen(filename, "r")) == NULL)
{
FatalError("Failed to open config file \"%s\",
check the filename "
"and try again\n", filename);
}

You actually open the file *twice*, causing a file
descriptor leak (because fclose() will only close one
of these FILE* streams) and probably a minor memory
leak too. Note that you will leak 1 descriptor thanks
to this duplicated fopen() every time barnyard is
HUPped & reloads it's config.

If you just want to check accessability, try using
access() before fopen().

Discussion

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks