Remove use of HeapAlloc and HeapPop. (#2455)

This commit is contained in:
David Anderson
2026-05-03 13:48:28 -07:00
committed by GitHub
parent 6739b0c280
commit 07735c1fe2
2 changed files with 6 additions and 21 deletions
+5 -20
View File
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <memory>
#include "common_logic.h"
#include "CellArray.h"
#include <IHandleSys.h>
@@ -227,16 +228,10 @@ static cell_t sm_SortStrings_Legacy(IPluginContext *pContext, const cell_t *para
pContext->LocalToPhysAddr(params[1], &array);
/** HACKHACK - back up the old indices, replace the indices with something easier */
cell_t amx_addr, *phys_addr;
int err;
if ((err=pContext->HeapAlloc(array_size, &amx_addr, &phys_addr)) != SP_ERROR_NONE)
{
pContext->ThrowNativeErrorEx(err, "Ran out of memory to sort");
return 0;
}
auto phys_addr = std::make_unique<cell_t[]>(array_size);
g_CurStringArray = array;
g_CurRebaseMap = phys_addr;
g_CurRebaseMap = phys_addr.get();
for (int i=0; i<array_size; i++)
{
@@ -268,8 +263,6 @@ static cell_t sm_SortStrings_Legacy(IPluginContext *pContext, const cell_t *para
array[i] = ((char *)&array[array[i]] + phys_addr[array[i]]) - (char *)&array[i];
}
pContext->HeapPop(amx_addr);
g_CurStringArray = NULL;
g_CurRebaseMap = NULL;
@@ -449,13 +442,7 @@ static cell_t sm_SortCustom2D_Legacy(IPluginContext *pContext, const cell_t *par
}
/** back up the old indices, replace the indices with something easier */
cell_t amx_addr, *phys_addr;
int err;
if ((err=pContext->HeapAlloc(array_size, &amx_addr, &phys_addr)) != SP_ERROR_NONE)
{
pContext->ThrowNativeErrorEx(err, "Ran out of memory to sort");
return 0;
}
auto phys_addr = std::make_unique<cell_t[]>(array_size);
sort_info oldinfo = g_SortInfo;
@@ -467,7 +454,7 @@ static cell_t sm_SortCustom2D_Legacy(IPluginContext *pContext, const cell_t *par
/** Same process as in strings, back up the old indices for later fixup */
g_SortInfo.array_base = array;
g_SortInfo.array_remap = phys_addr;
g_SortInfo.array_remap = phys_addr.get();
for (int i=0; i<array_size; i++)
{
@@ -486,8 +473,6 @@ static cell_t sm_SortCustom2D_Legacy(IPluginContext *pContext, const cell_t *par
array[i] = ((char *)&array[array[i]] + phys_addr[array[i]]) - (char *)&array[i];
}
pContext->HeapPop(amx_addr);
g_SortInfo = oldinfo;
return 1;