fixed a serious potential bug with swapping plugins to debug mode, leaving stale function pointers without plugin removal
2 * ===============================================================
3 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
4 * ===============================================================
6 * This file is not open source and may not be copied without explicit
7 * written permission of AlliedModders LLC. This file may not be redistributed
8 * in whole or significant part.
9 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
14 #include "sm_globals.h"
15 #include "HandleSys.h"
16 #include "PluginSys.h"
18 static cell_t sm_IsValidHandle(IPluginContext *pContext, const cell_t *params)
20 Handle_t hndl = static_cast<Handle_t>(params[1]);
22 HandleError err = g_HandleSys.ReadHandle(hndl, 0, NULL, NULL);
24 if (err != HandleError_Access
25 && err != HandleError_None)
33 static cell_t sm_CloseHandle(IPluginContext *pContext, const cell_t *params)
35 Handle_t hndl = static_cast<Handle_t>(params[1]);
39 sec.pOwner = pContext->GetIdentity();
41 HandleError err = g_HandleSys.FreeHandle(hndl, &sec);
43 if (err == HandleError_None)
46 } else if (err == HandleError_Access) {
49 return pContext->ThrowNativeError("Handle %x is invalid (error %d)", hndl, err);
53 static cell_t sm_CloneHandle(IPluginContext *pContext, const cell_t *params)
56 Handle_t hndl = static_cast<Handle_t>(params[1]);
58 IdentityToken_t *pNewOwner;
62 pNewOwner = pContext->GetIdentity();
64 Handle_t hPlugin = static_cast<Handle_t>(params[2]);
65 IPlugin *pPlugin = g_PluginSys.PluginFromHandle(hPlugin, &err);
68 return pContext->ThrowNativeError("Plugin handle %x is invalid (error %d)", hndl, err);
70 pNewOwner = pPlugin->GetIdentity();
73 err = g_HandleSys.CloneHandle(hndl, &new_hndl, pNewOwner, NULL);
75 if (err == HandleError_Access)
78 } else if (err == HandleError_None) {
81 return pContext->ThrowNativeError("Handle %x cannot be cloned because it is invalid (error %d)", hndl, err);
85 REGISTER_NATIVES(handles)
87 {"IsValidHandle", sm_IsValidHandle},
88 {"CloseHandle", sm_CloseHandle},
89 {"CloneHandle", sm_CloneHandle},