Fix memory leak in Regex extension. (#572)
* Fix memory leak in Regex extension. "x" is never deleted when compile fails. * Handle handle allocation failures. Handle allocation failures also result in memory leaks. * Fix typo.
This commit is contained in:
parent
ad3588d0aa
commit
fd399b9b4b
@ -87,10 +87,20 @@ static cell_t CompileRegex(IPluginContext *pCtx, const cell_t *params)
|
||||
const char *err = x->mError;
|
||||
*eOff = x->mErrorOffset;
|
||||
pCtx->StringToLocal(params[3], params[4], err ? err:"unknown");
|
||||
delete x;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return g_pHandleSys->CreateHandle(g_RegexHandle, (void*)x, pCtx->GetIdentity(), myself->GetIdentity(), NULL);
|
||||
HandleError error = HandleError_None;
|
||||
Handle_t regexHandle = g_pHandleSys->CreateHandle(g_RegexHandle, (void*)x, pCtx->GetIdentity(), myself->GetIdentity(), &error);
|
||||
if (!regexHandle || error != HandleError_None)
|
||||
{
|
||||
delete x;
|
||||
pCtx->ReportError("Allocation of regex handle failed, error code #%d", error);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return regexHandle;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user