diff --git a/sp/src/public/vscript/ivscript.h b/sp/src/public/vscript/ivscript.h index 88f4771a5b..de0842fdf5 100644 --- a/sp/src/public/vscript/ivscript.h +++ b/sp/src/public/vscript/ivscript.h @@ -431,7 +431,29 @@ struct ScriptVariant_t void operator=( QAngle &&vec ) { m_type = FIELD_VECTOR; m_pAngle = new QAngle( vec ); m_flags |= SV_FREE; } #endif - void Free() { if ( ( m_flags & SV_FREE ) && ( m_type == FIELD_HSCRIPT || m_type == FIELD_VECTOR || m_type == FIELD_CSTRING ) ) delete m_pszString; } // Generally only needed for return results + void Free() + { + // Generally only needed for return results + if ( ! ( m_flags & SV_FREE ) ) + { + return; + } + + switch ( m_type ) + { + case FIELD_VECTOR: + // QAngle and Vector share the type FIELD_VECTOR + // both are trivial to desctruct, so it should be fine to delete QAngle as Vector (or vice versa) + delete m_pVector; + return; + + case FIELD_CSTRING: + free( (char*)m_pszString ); + return; + } + + AssertMsg( 0, "Don't know how to free script variant of type %d", m_type ); + } template T Get()