mirror of
https://github.com/alliedmodders/metamod-source.git
synced 2025-02-26 19:54:14 +01:00
fixed bug where cproto pointers could be stale from removed plugins
--HG-- extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40182
This commit is contained in:
parent
7078132342
commit
50fe3e72d9
@ -1083,6 +1083,38 @@ namespace SourceHook
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// CProto
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
char *CSourceHookImpl::CProto::DupProto(const char *p)
|
||||
{
|
||||
char *newproto;
|
||||
if (*p)
|
||||
{
|
||||
size_t len = strlen(p);
|
||||
newproto = new char[len+1];
|
||||
memcpy(newproto, p, len+1);
|
||||
} else {
|
||||
const ProtoInfo *pi1 = reinterpret_cast<const ProtoInfo *>(p);
|
||||
int *ar_copy = new int[pi1->numOfParams + 1];
|
||||
for (int i = 0; i <= pi1->numOfParams; i++)
|
||||
ar_copy[i] = pi1->params[i];
|
||||
ProtoInfo *copy = new ProtoInfo(pi1->retTypeSize, pi1->numOfParams, ar_copy);
|
||||
newproto = reinterpret_cast<char *>(copy);
|
||||
}
|
||||
|
||||
return newproto;
|
||||
}
|
||||
|
||||
void CSourceHookImpl::CProto::FreeProto(char *prot)
|
||||
{
|
||||
if (*prot)
|
||||
{
|
||||
delete [] prot;
|
||||
} else {
|
||||
ProtoInfo *pi = reinterpret_cast<ProtoInfo *>(prot);
|
||||
delete [] pi->params;
|
||||
delete pi;
|
||||
}
|
||||
}
|
||||
|
||||
bool CSourceHookImpl::CProto::Equal(const char *p1, const char *p2)
|
||||
{
|
||||
if (*p1 && *p2) // Case1: Both old
|
||||
|
@ -154,25 +154,34 @@ namespace SourceHook
|
||||
private:
|
||||
class CProto
|
||||
{
|
||||
const char *m_Proto;
|
||||
char *m_Proto;
|
||||
|
||||
static bool Equal(const char *p1, const char *p2);
|
||||
char *DupProto(const char *src);
|
||||
void FreeProto(char *prot);
|
||||
public:
|
||||
CProto(const char *szProto) : m_Proto(szProto)
|
||||
CProto(const char *szProto) : m_Proto(DupProto(szProto))
|
||||
{
|
||||
}
|
||||
|
||||
CProto(const CProto &other) : m_Proto(other.m_Proto)
|
||||
CProto(const CProto &other) : m_Proto(DupProto(other.m_Proto))
|
||||
{
|
||||
}
|
||||
|
||||
~CProto()
|
||||
{
|
||||
FreeProto(m_Proto);
|
||||
m_Proto = NULL;
|
||||
}
|
||||
|
||||
void operator = (const char *szProto)
|
||||
{
|
||||
m_Proto = szProto;
|
||||
m_Proto = DupProto(szProto);
|
||||
}
|
||||
|
||||
void operator = (const CProto &other)
|
||||
{
|
||||
m_Proto = other.m_Proto;
|
||||
m_Proto = DupProto(other.m_Proto);
|
||||
}
|
||||
|
||||
bool operator == (const char *szProto) const
|
||||
|
Loading…
x
Reference in New Issue
Block a user