mirror of
https://github.com/ValveSoftware/source-sdk-2013.git
synced 2025-04-09 03:24:52 +00:00
Fix memory leak from unreleased script variants
This commit is contained in:
parent
0759e2e8e1
commit
cb0d1cc25c
2 changed files with 71 additions and 15 deletions
|
@ -1159,22 +1159,27 @@ bool ScriptSendGlobalGameEvent( const char *szName, HSCRIPT params )
|
|||
if ( vKey.GetType() != FIELD_CSTRING )
|
||||
{
|
||||
Log_Msg( LOG_VScript, "VSCRIPT: ScriptSendRealGameEvent: Key must be a FIELD_CSTRING" );
|
||||
continue;
|
||||
}
|
||||
const char *pszKeyName = (const char *)vKey;
|
||||
switch ( vValue.GetType() )
|
||||
else
|
||||
{
|
||||
case FIELD_BOOLEAN: event->SetBool ( pszKeyName, (bool)vValue ); break;
|
||||
case FIELD_FLOAT: event->SetFloat ( pszKeyName, (float)vValue ); break;
|
||||
case FIELD_INTEGER: event->SetInt ( pszKeyName, (int)vValue ); break;
|
||||
case FIELD_CSTRING: event->SetString( pszKeyName, (const char *)vValue ); break;
|
||||
case FIELD_UINT64: event->SetUint64( pszKeyName, (uint64)vValue ); break;
|
||||
default:
|
||||
const char *pszKeyName = (const char *)vKey;
|
||||
switch ( vValue.GetType() )
|
||||
{
|
||||
Log_Msg( LOG_VScript, "VSCRIPT: ScriptSendRealGameEvent: Don't understand FIELD_TYPE of value for key %s.", pszKeyName );
|
||||
break;
|
||||
case FIELD_BOOLEAN: event->SetBool ( pszKeyName, (bool)vValue ); break;
|
||||
case FIELD_FLOAT: event->SetFloat ( pszKeyName, (float)vValue ); break;
|
||||
case FIELD_INTEGER: event->SetInt ( pszKeyName, (int)vValue ); break;
|
||||
case FIELD_CSTRING: event->SetString( pszKeyName, (const char *)vValue ); break;
|
||||
case FIELD_UINT64: event->SetUint64( pszKeyName, (uint64)vValue ); break;
|
||||
default:
|
||||
{
|
||||
Log_Msg( LOG_VScript, "VSCRIPT: ScriptSendRealGameEvent: Don't understand FIELD_TYPE of value for key %s.", pszKeyName );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_pScriptVM->ReleaseValue( vKey );
|
||||
g_pScriptVM->ReleaseValue( vValue );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1809,15 +1814,31 @@ static bool Script_TraceLineEx( HSCRIPT hTable )
|
|||
bool bNoParams = false;
|
||||
|
||||
if (g_pScriptVM->GetValue( hTable, "start", &rval ) )
|
||||
{
|
||||
vStart = rval;
|
||||
g_pScriptVM->ReleaseValue( rval );
|
||||
}
|
||||
else
|
||||
{
|
||||
bNoParams = true;
|
||||
}
|
||||
|
||||
if (g_pScriptVM->GetValue( hTable, "end", &rval ) )
|
||||
{
|
||||
vEnd = rval;
|
||||
g_pScriptVM->ReleaseValue( rval );
|
||||
}
|
||||
else
|
||||
{
|
||||
bNoParams = true;
|
||||
}
|
||||
|
||||
if (g_pScriptVM->GetValue( hTable, "mask", &rval ))
|
||||
{
|
||||
mask = rval;
|
||||
g_pScriptVM->ReleaseValue( rval );
|
||||
}
|
||||
|
||||
if (bNoParams)
|
||||
{
|
||||
Warning("Didnt supply start and end to Script TraceLine call, failing, setting called to false\n");
|
||||
|
@ -1827,6 +1848,7 @@ static bool Script_TraceLineEx( HSCRIPT hTable )
|
|||
if (g_pScriptVM->GetValue( hTable, "ignore", &rval ))
|
||||
{
|
||||
pIgnoreEnt = ToEnt((HSCRIPT)rval);
|
||||
g_pScriptVM->ReleaseValue( rval );
|
||||
}
|
||||
trace_t tr;
|
||||
UTIL_TraceLine( vStart, vEnd, mask, pIgnoreEnt, coll, &tr );
|
||||
|
@ -1848,24 +1870,44 @@ static bool Script_TraceHull( HSCRIPT hTable )
|
|||
bool bNoParams = false;
|
||||
|
||||
if (g_pScriptVM->GetValue( hTable, "start", &rval ) )
|
||||
{
|
||||
vStart = rval;
|
||||
g_pScriptVM->ReleaseValue( rval );
|
||||
}
|
||||
else
|
||||
{
|
||||
bNoParams = true;
|
||||
}
|
||||
|
||||
if (g_pScriptVM->GetValue( hTable, "end", &rval ) )
|
||||
{
|
||||
vEnd = rval;
|
||||
g_pScriptVM->ReleaseValue( rval );
|
||||
}
|
||||
else
|
||||
{
|
||||
bNoParams = true;
|
||||
}
|
||||
|
||||
if (g_pScriptVM->GetValue( hTable, "hullmin", &rval ) )
|
||||
{
|
||||
vHullMin = rval;
|
||||
g_pScriptVM->ReleaseValue( rval );
|
||||
}
|
||||
else
|
||||
{
|
||||
bNoParams = true;
|
||||
}
|
||||
|
||||
if (g_pScriptVM->GetValue( hTable, "hullmax", &rval ) )
|
||||
{
|
||||
vHullMax = rval;
|
||||
g_pScriptVM->ReleaseValue( rval );
|
||||
}
|
||||
else
|
||||
{
|
||||
bNoParams = true;
|
||||
}
|
||||
|
||||
if (bNoParams)
|
||||
{
|
||||
|
@ -1877,11 +1919,13 @@ static bool Script_TraceHull( HSCRIPT hTable )
|
|||
if (g_pScriptVM->GetValue( hTable, "mask", &rval ))
|
||||
{
|
||||
mask = rval;
|
||||
g_pScriptVM->ReleaseValue( rval );
|
||||
}
|
||||
|
||||
if (g_pScriptVM->GetValue( hTable, "ignore", &rval ))
|
||||
{
|
||||
pIgnoreEnt = ToEnt((HSCRIPT)rval);
|
||||
g_pScriptVM->ReleaseValue( rval );
|
||||
}
|
||||
|
||||
trace_t tr;
|
||||
|
|
|
@ -550,6 +550,14 @@ public:
|
|||
virtual bool SetValue( HSCRIPT hScope, const char *pszKey, const char *pszValue ) = 0;
|
||||
virtual bool SetValue( HSCRIPT hScope, const char *pszKey, const ScriptVariant_t &value ) = 0;
|
||||
bool SetValue( const char *pszKey, const ScriptVariant_t &value ) { return SetValue(NULL, pszKey, value ); }
|
||||
// temporary objects take this path to be automatically released
|
||||
bool SetValue( HSCRIPT hScope, const char* pszKey, ScriptVariant_t&& value )
|
||||
{
|
||||
bool bRet = SetValue( hScope, pszKey, value );
|
||||
value.Free();
|
||||
return bRet;
|
||||
}
|
||||
bool SetValue( const char *pszKey, ScriptVariant_t&& value ) { return SetValue(NULL, pszKey, std::move(value)); }
|
||||
|
||||
virtual void CreateTable( ScriptVariant_t &Table ) = 0;
|
||||
virtual int GetNumTableEntries( HSCRIPT hScope ) = 0;
|
||||
|
@ -570,7 +578,9 @@ public:
|
|||
{
|
||||
ScriptVariant_t variant;
|
||||
GetValue( hScope, pszKey, &variant );
|
||||
return variant.Get<T>();
|
||||
T ret = variant.Get<T>();
|
||||
variant.Free();
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -1395,11 +1405,13 @@ public:
|
|||
template <>
|
||||
inline HSCRIPT IScriptVM::Get<HSCRIPT>( HSCRIPT hScope, const char *pszKey )
|
||||
{
|
||||
HSCRIPT ret = nullptr;
|
||||
ScriptVariant_t variant;
|
||||
GetValue( hScope, pszKey, &variant );
|
||||
if ( variant.GetType() == FIELD_VOID )
|
||||
return NULL;
|
||||
return variant.Get<HSCRIPT>();
|
||||
if ( variant.GetType() != FIELD_VOID )
|
||||
ret = variant.Get<HSCRIPT>();
|
||||
variant.Free();
|
||||
return ret;
|
||||
}
|
||||
|
||||
#include "tier0/memdbgoff.h"
|
||||
|
|
Loading…
Reference in a new issue