From a327a80fcd2b069aabac875356f92e0c821447b1 Mon Sep 17 00:00:00 2001 From: bottiger1 <55270538+bottiger1@users.noreply.github.com> Date: Sun, 29 Mar 2026 11:11:12 -0700 Subject: [PATCH] Fix HookConVarChange giving stale convar pointers when a plugin made the convar longer, triggering realloc (#2423) --- core/ConVarManager.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/ConVarManager.cpp b/core/ConVarManager.cpp index dcd5d8ed..2a8c5043 100644 --- a/core/ConVarManager.cpp +++ b/core/ConVarManager.cpp @@ -650,10 +650,16 @@ void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue, float { ConVarReentrancyGuard guard(pConVar); + /* Copy the new value to a local buffer so it survives reentrant + * ChangeStringValue calls that may delete[] + reallocate m_pszString + * while the forward is still iterating plugin callbacks. */ + char newValue[512]; + strncpy(newValue, pConVar->GetString(), sizeof(newValue)); + /* Now call forwards in plugins that have hooked this */ pForward->PushCell(pInfo->handle); pForward->PushString(oldValue); - pForward->PushString(pConVar->GetString()); + pForward->PushString(newValue); pForward->Execute(NULL); } }