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:
parent
dca15ebabf
commit
9021b23bc2
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user