Fix strdup() leaks

This commit is contained in:
Alexander 'z33ky' Hirsch
2021-04-25 22:47:55 +02:00
parent a75b0b7d58
commit 036fbda906
4 changed files with 43 additions and 32 deletions

View File

@@ -2511,7 +2511,7 @@ class CBreakableGibShooter : public CBaseEntity
DECLARE_DATADESC();
public:
const char *GetRandomTemplateModel( CPointTemplate *pTemplate );
int GetRandomTemplateModelIndex( CPointTemplate *pTemplate );
void Precache( void );
@@ -2560,19 +2560,20 @@ END_DATADESC()
LINK_ENTITY_TO_CLASS( env_break_shooter, CBreakableGibShooter );
const char *CBreakableGibShooter::GetRandomTemplateModel( CPointTemplate *pTemplate )
int CBreakableGibShooter::GetRandomTemplateModelIndex( CPointTemplate *pTemplate )
{
int iIndex = RandomInt( 0, pTemplate->GetNumTemplates() );
char *iszTemplate = (char*)(STRING(Templates_FindByIndex(pTemplate->GetTemplateIndexForTemplate(iIndex))));
char *iszTemplate = strdup(STRING(Templates_FindByIndex(pTemplate->GetTemplateIndexForTemplate(iIndex))));
CEntityMapData entData( iszTemplate );
// This might seem a little messy, but I think it's cheaper than creating the entity.
char szModel[MAPKEY_MAXLENGTH];
if (!entData.ExtractValue("model", szModel))
return NULL;
bool modelExtracted = entData.ExtractValue("model", szModel);
return strdup(szModel);
free(iszTemplate);
return modelinfo->GetModelIndex( modelExtracted ? szModel : NULL );
}
void CBreakableGibShooter::Precache( void )
@@ -2604,7 +2605,7 @@ void CBreakableGibShooter::Shoot( void )
if (m_iModelType == MODELTYPE_BREAKABLECHUNKS)
iModelIndex = modelinfo->GetModelIndex( g_PropDataSystem.GetRandomChunkModel( STRING( GetModelName() ) ) );
else if (m_iModelType == MODELTYPE_TEMPLATE)
iModelIndex = modelinfo->GetModelIndex( GetRandomTemplateModel(pTemplate) );
iModelIndex = GetRandomTemplateModelIndex( pTemplate );
// All objects except the first one in this run are marked as slaves...
int slaveFlag = 0;