View Single Post
c0ldfyr3
AlliedModders Donor
Join Date: Aug 2005
Location: Ireland
Old 10-23-2010 , 16:48   Re: Heap Corruption from Cvar Deconstruction? - PM I'm lookin at you here ;)
Reply With Quote #2

In case it helps I'm appending my Callback functionality, the reason it's so hairy is due to changes since the corruption started happening, I've been trying my hardest to avoid any situation where a ConVar may be created in my callback but to no avail...

PHP Code:
char sTmp[100];
char sNewVarName[100];
char sPrefix[8];

// Create string name of the alternate cvar.
if ( lZombieVar == CVAR_ORIGINAL )
{
    
Q_strncpysPrefix"zm_"sizeofsPrefix ) );
    
Q_StrRightsNameQ_strlensName ) - 7sTmp100 );
}
else 
// CVAR_SHORT
{
    
Q_strncpysPrefix"zombie_"sizeofsPrefix ) );
    
Q_StrRightsNameQ_strlensName ) - 3sTmp100 );
}
Q_snprintfsNewVarNamesizeofsNewVarName ), "%s%s"sPrefixsTmp );

// Get reference to ConVars.
ConVarRef cRef ConVarRefsName );
ConVarRef cNewRef ConVarRefsNewVarName );

// Set alternate cvar values.
cNewRef.m_pConVarState->m_fValue cRef.m_pConVarState->GetFloat();
cNewRef.m_pConVarState->m_nValue cRef.m_pConVarState->GetInt();

// Set string value...
char sString[5120] = "";
Q_strncpy(sString, (char*)cRef.m_pConVarState->GetString(), 5120 );
if ( 
Q_strlensString ) > )
{
    
// Only set this pointer to a value value if the string exists, otherwise maybe it's what's causing the issue as the issue is happening during deleting of this string! Maybe it's because this isn't a string pointer and is being destroyed at the end of my function?? I'm afraid to use SetValue in case it fires the cvar again but this can be hacked.
    
Q_strncpycNewRef.m_pConVarState->m_pszStringsStringQ_strlensString ) + ); 
}

// If it was the short version we want to fire anything that happens during the firing of the long version, I'm still not 100% sure if we need this, the code above (which isn't in this post) could be amended instead.
if ( lZombieVar == CVAR_SHORT )
{
    
char sCommand[1024];
    if ( 
Q_strlen(sNewVarName) == || Q_strlen(sString) == )
    {
        
Assertfalse ); // Should never happen but...
    
}
    
Q_snprintfsCommandsizeofsCommand ), "%s \"%s\"\n"sNewVarNamesString ); // Create command.
    
m_Engine->ServerCommandsCommand ); // Could be tidied but useful for now.

__________________
c0ldfyr3 is offline
Send a message via MSN to c0ldfyr3 Send a message via Yahoo to c0ldfyr3