From 5d58774813d4ecd4fc9f8230f8d5446457eb2ed5 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 23 Mar 2010 14:21:33 +0100 Subject: streamline dynafile cache entry deletion a bit The old code looks a bit "strange", though not necessarily incorrect. The new code looks correct and is probably less irritating during bug hunting. --- tools/omfile.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/omfile.c b/tools/omfile.c index ae5f350d..91bcf0c2 100644 --- a/tools/omfile.c +++ b/tools/omfile.c @@ -286,19 +286,18 @@ dynaFileDelCacheEntry(dynaFileCacheEntry **pCache, int iEntry, int bFreeEntry) DBGPRINTF("Removed entry %d for file '%s' from dynaCache.\n", iEntry, pCache[iEntry]->pName == NULL ? UCHAR_CONSTANT("[OPEN FAILED]") : pCache[iEntry]->pName); -// RG: check the "open failed" case -- can this cause trouble (but do we have that situation?) - /* if the name is NULL, this is an improperly initialized entry which - * needs to be discarded. In this case, neither the file is to be closed - * nor the name to be freed. - */ + if(pCache[iEntry]->pName != NULL) { - if(pCache[iEntry]->pStrm != NULL) - strm.Destruct(&pCache[iEntry]->pStrm); -// RG: pStrm should now be NULL... d_free(pCache[iEntry]->pName); pCache[iEntry]->pName = NULL; } + if(pCache[iEntry]->pStrm != NULL) { + strm.Destruct(&pCache[iEntry]->pStrm); + if(pCache[iEntry]->pStrm != NULL) /* safety check -- TODO: remove if no longer necessary */ + abort(); + } + if(bFreeEntry) { d_free(pCache[iEntry]); pCache[iEntry] = NULL; -- cgit