1.1 --- a/core/HandleSys.h Sat Apr 24 21:10:23 2010 -0400
1.2 +++ b/core/HandleSys.h Tue Apr 27 21:03:20 2010 -0700
1.3 @@ -160,6 +160,9 @@
1.4 HandleError *err);
1.5
1.6 void Dump(HANDLE_REPORTER rep);
1.7 +
1.8 + /* Bypasses security checks. */
1.9 + Handle_t FastCloneHandle(Handle_t hndl);
1.10 protected:
1.11 /**
1.12 * Decodes a handle with sanity and security checking.
1.13 @@ -170,6 +173,9 @@
1.14 unsigned int *index,
1.15 bool ignoreFree=false);
1.16
1.17 + Handle_t FastCloneHandle(QHandle *pHandle, unsigned int index);
1.18 + void GetHandleUnchecked(Handle_t hndl, QHandle *& pHandle, unsigned int &index);
1.19 +
1.20 /**
1.21 * Creates a basic handle and sets its reference count to 1.
1.22 * Does not do any type or security checking.
1.23 @@ -222,4 +228,27 @@
1.24
1.25 extern HandleSystem g_HandleSys;
1.26
1.27 +struct AutoHandleRooter
1.28 +{
1.29 +public:
1.30 + AutoHandleRooter(Handle_t hndl)
1.31 + {
1.32 + if (hndl != BAD_HANDLE)
1.33 + this->hndl = g_HandleSys.FastCloneHandle(hndl);
1.34 + else
1.35 + this->hndl = BAD_HANDLE;
1.36 + }
1.37 +
1.38 + ~AutoHandleRooter()
1.39 + {
1.40 + if (hndl != BAD_HANDLE)
1.41 + {
1.42 + HandleSecurity sec(g_pCoreIdent, g_pCoreIdent);
1.43 + g_HandleSys.FreeHandle(hndl, &sec);
1.44 + }
1.45 + }
1.46 +private:
1.47 + Handle_t hndl;
1.48 +};
1.49 +
1.50 #endif //_INCLUDE_SOURCEMOD_HANDLESYSTEM_H_