From a6779df21ce838c90c19d4c04aff5dd5972dece4 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Thu, 3 Mar 2022 09:02:41 -0800 Subject: [PATCH] dbReadDatabaseFP() always fclose() --- .../database/src/ioc/dbStatic/dbLexRoutines.c | 9 +++++++-- .../database/src/ioc/dbStatic/dbStaticLib.h | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/modules/database/src/ioc/dbStatic/dbLexRoutines.c b/modules/database/src/ioc/dbStatic/dbLexRoutines.c index 13af8de3e..3aac8e4b1 100644 --- a/modules/database/src/ioc/dbStatic/dbLexRoutines.c +++ b/modules/database/src/ioc/dbStatic/dbLexRoutines.c @@ -223,8 +223,10 @@ static long dbReadCOM(DBBASE **ppdbbase,const char *filename, FILE *fp, epicsPrintf("dbReadCOM: Parser stack dirty %d\n", ellCount(&tempList)); } - if (getIocState() != iocVoid) - return -2; + if (getIocState() != iocVoid) { + status = -2; + goto cleanup; + } if(*ppdbbase == 0) *ppdbbase = dbAllocBase(); pdbbase = *ppdbbase; @@ -277,6 +279,7 @@ static long dbReadCOM(DBBASE **ppdbbase,const char *filename, FILE *fp, pinputFile->fp = fp1; } else { pinputFile->fp = fp; + fp = NULL; } pinputFile->line_num = 0; pinputFileNow = pinputFile; @@ -332,6 +335,8 @@ cleanup: if(my_buffer) free((void *)my_buffer); my_buffer = NULL; freeInputFileList(); + if(fp) + fclose(fp); return(status); } diff --git a/modules/database/src/ioc/dbStatic/dbStaticLib.h b/modules/database/src/ioc/dbStatic/dbStaticLib.h index ea42efccb..568517edd 100644 --- a/modules/database/src/ioc/dbStatic/dbStaticLib.h +++ b/modules/database/src/ioc/dbStatic/dbStaticLib.h @@ -57,8 +57,26 @@ DBCORE_API void dbCopyEntryContents(DBENTRY *pfrom, DBCORE_API extern int dbBptNotMonotonic; +/** \brief Open .dbd or .db file and read definitions. + * \param ppdbbase The database. Typically the "pdbbase" global + * \param filename Filename to read/search. May be absolute, or relative. + * \param path If !NULL, search path when filename is relative, of for 'include' statements. + * Split by ':' or ';' (cf. OSI_PATH_LIST_SEPARATOR) + * \param substitutions If !NULL, macro definitions like "NAME=VAL,OTHER=SOME" + * \return 0 on success + */ DBCORE_API long dbReadDatabase(DBBASE **ppdbbase, const char *filename, const char *path, const char *substitutions); +/** \brief Read definitions from already opened .dbd or .db file. + * \param ppdbbase The database. Typically the "&pdbbase" global + * \param fp FILE* from which to read definitions. Will always be fclose()'d + * \param path If !NULL, search path when filename is relative, of for 'include' statements. + * Split by ':' or ';' (cf. OSI_PATH_LIST_SEPARATOR) + * \param substitutions If !NULL, macro definitions like "NAME=VAL,OTHER=SOME" + * \return 0 on success + * + * \note This function will always close the provided 'fp'. + */ DBCORE_API long dbReadDatabaseFP(DBBASE **ppdbbase, FILE *fp, const char *path, const char *substitutions); DBCORE_API long dbPath(DBBASE *pdbbase, const char *path);