Fixed clientprefs prefab menu double free crash (bug 5374, r=asherkin).

This commit is contained in:
Nicholas Hastings 2012-07-03 07:51:12 -04:00
parent 49ad25d001
commit 3479e452de
3 changed files with 25 additions and 4 deletions

View File

@ -105,6 +105,7 @@ bool ClientPrefs::SDK_OnLoad(char *error, size_t maxlength, bool late)
sharesys->AddNatives(myself, g_ClientPrefNatives);
sharesys->RegisterLibrary(myself, "clientprefs");
identity = sharesys->CreateIdentity(sharesys->CreateIdentType("ClientPrefs"), this);
g_CookieManager.cookieDataLoadedForward = forwards->CreateForward("OnClientCookiesCached", ET_Ignore, 1, NULL, Param_Cell);
g_CookieType = handlesys->CreateType("Cookie",
@ -124,7 +125,7 @@ bool ClientPrefs::SDK_OnLoad(char *error, size_t maxlength, bool late)
NULL);
IMenuStyle *style = menus->GetDefaultStyle();
g_CookieManager.clientMenu = style->CreateMenu(&g_Handler, NULL);
g_CookieManager.clientMenu = style->CreateMenu(&g_Handler, identity);
g_CookieManager.clientMenu->SetDefaultTitle("Client Settings:");
plsys->AddPluginsListener(&g_CookieManager);
@ -191,10 +192,17 @@ void ClientPrefs::SDK_OnUnload()
forwards->ReleaseForward(g_CookieManager.cookieDataLoadedForward);
g_CookieManager.clientMenu->Destroy();
HandleSecurity sec = HandleSecurity(identity, identity);
HandleError err = handlesys->FreeHandle(g_CookieManager.clientMenu->GetHandle(), &sec);
if (HandleError_None != err)
{
g_pSM->LogError(myself, "Error %d when attempting to free client menu handle", err);
}
phrases->Destroy();
sharesys->DestroyIdentity( identity );
plsys->RemovePluginsListener(&g_CookieManager);
playerhelpers->RemoveClientListener(&g_CookieManager);
@ -470,6 +478,11 @@ bool Translate(char *buffer,
return true;
}
IdentityToken_t *ClientPrefs::GetIdentity() const
{
return identity;
}
const char *ClientPrefs::GetExtensionVerString()
{
return SM_FULL_VERSION;

View File

@ -140,6 +140,8 @@ public:
*/
//virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
#endif
public:
IdentityToken_t *GetIdentity() const;
public:
IDBDriver *Driver;
IDatabase *Database;
@ -152,6 +154,7 @@ public:
private:
SourceHook::List<TQueryOp *> cachedQueries;
IMutex *queryMutex;
IdentityToken_t *identity;
};
class CookieTypeHandler : public IHandleTypeDispatch

View File

@ -57,7 +57,7 @@ void ClientMenuHandler::OnMenuSelect(IBaseMenu *menu, int client, unsigned int i
return;
}
IBaseMenu *submenu = menus->GetDefaultStyle()->CreateMenu(&g_AutoHandler, NULL);
IBaseMenu *submenu = menus->GetDefaultStyle()->CreateMenu(&g_AutoHandler, g_ClientPrefs.GetIdentity());
char message[256];
@ -175,5 +175,10 @@ void AutoMenuHandler::OnMenuSelect(SourceMod::IBaseMenu *menu, int client, unsig
void AutoMenuHandler::OnMenuEnd(IBaseMenu *menu, MenuEndReason reason)
{
menu->Destroy(true);
HandleSecurity sec = HandleSecurity(g_ClientPrefs.GetIdentity(), g_ClientPrefs.GetIdentity());
HandleError err = handlesys->FreeHandle(menu->GetHandle(), &sec);
if (HandleError_None != err)
{
g_pSM->LogError(myself, "Error %d when attempting to free automenu handle", err);
}
}