Fix crash on OpenDirectory with use_valve_fs if path not found.

Also fixes minor memory leak on bad path.
This commit is contained in:
Nicholas Hastings 2014-10-27 17:27:53 -04:00
parent dca15ebabf
commit 9021b23bc2

View File

@ -179,7 +179,7 @@ private:
struct ValveDirectory
{
FileFindHandle_t hndl;
FileFindHandle_t hndl = -1;
char szFirstPath[PLATFORM_MAX_PATH];
bool bHandledFirstPath;
};
@ -282,7 +282,6 @@ static cell_t sm_OpenDirectory(IPluginContext *pContext, const cell_t *params)
{
size_t len = strlen(path);
char wildcardedPath[PLATFORM_MAX_PATH];
ValveDirectory *valveDir = new ValveDirectory;
snprintf(wildcardedPath, sizeof(wildcardedPath), "%s%s*", path, (path[len-1] != '/' && path[len-1] != '\\') ? "/" : "");
char *pathID;
@ -292,15 +291,18 @@ static cell_t sm_OpenDirectory(IPluginContext *pContext, const cell_t *params)
return 0;
}
ValveDirectory *valveDir = new ValveDirectory;
const char *pFirst = smcore.filesystem->FindFirstEx(wildcardedPath, pathID, &valveDir->hndl);
if (pFirst)
if (!pFirst)
{
valveDir->bHandledFirstPath = false;
strncpy(valveDir->szFirstPath, pFirst, sizeof(valveDir->szFirstPath));
delete valveDir;
return 0;
}
else
{
valveDir->bHandledFirstPath = true;
valveDir->bHandledFirstPath = false;
strncpy(valveDir->szFirstPath, pFirst, sizeof(valveDir->szFirstPath));
}
handle = handlesys->CreateHandle(g_ValveDirType, valveDir, pContext->GetIdentity(), g_pCoreIdent, NULL);