Fix potential fclose nullpointer core dumps

MFC after:	1 month
This commit is contained in:
Hellmuth Michaelis 2001-12-27 08:41:10 +00:00
parent 09ec4b8de7
commit 94530bc64f
3 changed files with 28 additions and 19 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
* Copyright (c) 1997, 2001 Hellmuth Michaelis. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -27,11 +27,9 @@
* i4b daemon - logging routines
* -----------------------------
*
* $Id: log.c,v 1.25 2000/10/09 12:53:29 hm Exp $
*
* $FreeBSD$
*
* last edit-date: [Mon Dec 13 21:47:28 1999]
* last edit-date: [Wed Dec 26 12:49:45 2001]
*
*---------------------------------------------------------------------------*/
@ -126,7 +124,7 @@ init_log(void)
void
finish_log(void)
{
if(uselogfile)
if(uselogfile && logfp)
{
fflush(logfp);
fclose(logfp);

View file

@ -29,7 +29,7 @@
*
* $FreeBSD$
*
* last edit-date: [Thu Oct 18 13:57:45 2001]
* last edit-date: [Wed Dec 26 12:51:00 2001]
*
*---------------------------------------------------------------------------*/
@ -775,8 +775,11 @@ reopenfiles(int dummy)
{
/* close file */
fflush(acctfp);
fclose(acctfp);
if(acctfp)
{
fflush(acctfp);
fclose(acctfp);
}
/* if user specified a suffix, rename the old file */

View file

@ -29,7 +29,7 @@
*
* $FreeBSD$
*
* last edit-date: [Fri Jul 20 19:16:27 2001]
* last edit-date: [Wed Dec 26 12:57:07 2001]
*
*---------------------------------------------------------------------------*/
@ -86,17 +86,17 @@ configure(char *filename, int reread)
yyin = fopen(filename, "r");
if(reread)
{
reset_scanner(yyin);
}
if (yyin == NULL)
if(yyin == NULL)
{
log(LL_ERR, "cannot fopen file [%s]", filename);
exit(1);
}
if(reread)
{
reset_scanner(yyin);
}
yyparse();
monitor_fixup_rights();
@ -465,8 +465,10 @@ cfg_setval(int keyword)
fclose(fp);
fp = fopen(yylval.str, "w");
if(fp != NULL)
{
fprintf(fp, "%d %d %d", (int)time(NULL), (int)time(NULL), 0);
fclose(fp);
fclose(fp);
}
}
}
else
@ -474,8 +476,10 @@ cfg_setval(int keyword)
DBGL(DL_RCCF, (log(LL_DBG, "entry %d: creating budget-callbacksfile %s", entrycount, yylval.str)));
fp = fopen(yylval.str, "w");
if(fp != NULL)
{
fprintf(fp, "%d %d %d", (int)time(NULL), (int)time(NULL), 0);
fclose(fp);
fclose(fp);
}
}
fp = fopen(yylval.str, "r");
@ -516,8 +520,10 @@ cfg_setval(int keyword)
fclose(fp);
fp = fopen(yylval.str, "w");
if(fp != NULL)
{
fprintf(fp, "%d %d %d", (int)time(NULL), (int)time(NULL), 0);
fclose(fp);
fclose(fp);
}
}
}
else
@ -525,8 +531,10 @@ cfg_setval(int keyword)
DBGL(DL_RCCF, (log(LL_DBG, "entry %d: creating budget-calloutsfile %s", entrycount, yylval.str)));
fp = fopen(yylval.str, "w");
if(fp != NULL)
{
fprintf(fp, "%d %d %d", (int)time(NULL), (int)time(NULL), 0);
fclose(fp);
fclose(fp);
}
}
fp = fopen(yylval.str, "r");