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