Skip to content

Server crash on removal callback called on unloaded plugin #3

@FortyTwoFortyTwo

Description

@FortyTwoFortyTwo

Tested in TF2 windows and linux with 2.2.0-detours7, i couldn't get to test whenever non-detour version would still crash but im pretty sure it does as i haven't seen any related changes between it.

I'm getting a lot of these crashes, but this one caught my eyes on how it happened, which it seems like it crashed here.

I have a plugin with several hook removal callback, and another plugin that automatically unloads plugin on map end. From what i can see it crashes when dhook tries to call a removal callback while plugin is being unloaded.

Smallest reproduce i can make:

  • Load below plugin named disabled/42test.smx
  • Join server
  • Change map
    This will unload plugin and dhook attempting to call OnHookRemoved, leading to a crash.
#include <sdktools>
#include <dhooks>

Handle g_hHookGetMaxHealth;

public void OnPluginStart()
{
	GameData hGameData = new GameData("sdkhooks.games");
	if (hGameData == null)
		SetFailState("Could not find sdkhooks.games gamedata");
	
	int iOffset = hGameData.GetOffset("GetMaxHealth");
	g_hHookGetMaxHealth = DHookCreate(iOffset, HookType_Entity, ReturnType_Int, ThisPointer_CBaseEntity);
	if (g_hHookGetMaxHealth == null)
		LogMessage("Failed to create hook: CTFPlayer::GetMaxHealth");
	
	delete hGameData;
	
	//Lateload
	for (int iClient = 1; iClient <= MaxClients; iClient++)
		if (IsClientInGame(iClient))
			OnClientPutInServer(iClient);
}

public void OnMapEnd()
{
	ServerCommand("sm plugins unload disabled/42test");
}

public void OnClientPutInServer(int iClient)
{
	DHookEntity(g_hHookGetMaxHealth, true, iClient, OnHookRemoved, GetMaxHealth);
}

public void OnHookRemoved(int iHookId)
{
}

public MRESReturn GetMaxHealth(int iClient, Handle hReturn)
{
	return MRES_Ignored;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions