dbReadDatabaseFP() always fclose()

This commit is contained in:
Michael Davidsaver
2022-03-03 09:02:41 -08:00
parent d8c5379453
commit a6779df21c
2 changed files with 25 additions and 2 deletions

View File

@@ -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);
}

View File

@@ -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);