Skip to content

Commit bf99e26

Browse files
committed
Fix DHookReturnParam handle leaking
1 parent 92b10b4 commit bf99e26

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

extensions/dhooks/src/handle.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace locals {
2020
std::unordered_map<std::uint32_t, cell_t> associated_handle;
2121
std::unordered_map<CGenericClass*, std::vector<std::uint32_t>> class_dynamichooks;
2222
std::unordered_set<void**> class_vtables;
23+
SourceMod::HandleSecurity* security = nullptr;
2324
}
2425

2526
ParamReturn::ParamReturn(const Capsule* capsule, GeneralRegister* generalregs, FloatRegister* floatregs, void* return_ptr) :
@@ -32,7 +33,9 @@ ParamReturn::ParamReturn(const Capsule* capsule, GeneralRegister* generalregs, F
3233

3334
ParamReturn::~ParamReturn() {
3435
if (_handle != BAD_HANDLE) {
35-
globals::handlesys->FreeHandle(_handle, nullptr);
36+
if (globals::handlesys->FreeHandle(_handle, locals::security) != SourceMod::HandleError_None) {
37+
globals::sourcemod->LogError(globals::myself, "Failed to delete ParamReturn handle. Contact a Sourcemod dev!");
38+
}
3639
}
3740
}
3841

@@ -324,6 +327,8 @@ class HookSetupDispatch : public SourceMod::IHandleTypeDispatch {
324327
HookSetupDispatch gHookSetupDispatcher;
325328

326329
void init() {
330+
locals::security = new SourceMod::HandleSecurity(globals::myself->GetIdentity(), globals::myself->GetIdentity());
331+
327332
SourceMod::HandleAccess security;
328333
globals::handlesys->InitAccessDefaults(nullptr, &security);
329334
// Do not allow cloning, the struct self-manage its handle

0 commit comments

Comments
 (0)