Don't call function pointers when they're NULL (fixes a segfault bug that occurs when a resource type without release function couldn't be loaded)

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@4896 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-05-03 10:24:36 +00:00
parent 46805bb32f
commit 31fda8026b
1 changed files with 12 additions and 3 deletions

View File

@ -463,7 +463,10 @@ BOOL resLoadFile(const char *pType, const char *pFile)
{ {
debug(LOG_ERROR, "resLoadFile: The load function for resource type \"%s\" failed for file \"%s\"", pType, pFile); debug(LOG_ERROR, "resLoadFile: The load function for resource type \"%s\" failed for file \"%s\"", pType, pFile);
FreeResourceFile(Resource); FreeResourceFile(Resource);
if (psT->release != NULL)
{
psT->release(pData); psT->release(pData);
}
return false; return false;
} }
@ -475,7 +478,10 @@ BOOL resLoadFile(const char *pType, const char *pFile)
if (!psT->fileLoad(aFileName, &pData)) if (!psT->fileLoad(aFileName, &pData))
{ {
debug(LOG_ERROR, "resLoadFile: The load function for resource type \"%s\" failed for file \"%s\"", pType, pFile); debug(LOG_ERROR, "resLoadFile: The load function for resource type \"%s\" failed for file \"%s\"", pType, pFile);
if (psT->release != NULL)
{
psT->release(pData); psT->release(pData);
}
return false; return false;
} }
} }
@ -493,8 +499,11 @@ BOOL resLoadFile(const char *pType, const char *pFile)
// LastResourceFilename may have been changed (e.g. by TEXPAGE loading) // LastResourceFilename may have been changed (e.g. by TEXPAGE loading)
psRes = resDataInit( GetLastResourceFilename(), HashStringIgnoreCase(GetLastResourceFilename()), pData, resBlockID ); psRes = resDataInit( GetLastResourceFilename(), HashStringIgnoreCase(GetLastResourceFilename()), pData, resBlockID );
if (!psRes) if (!psRes)
{
if (psT->release != NULL)
{ {
psT->release(pData); psT->release(pData);
}
return false; return false;
} }