From ba944e5675342fd55bc887e55c7794df4fb276be Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 11 Oct 2021 22:22:24 -0500 Subject: [PATCH] Support allocations up to 32767 bytes in the pool-based allocator. The previous limit was 4096 bytes, and trying to allocate more could lead to memory corruption. Raising the limit allows for longer string literals created via concatenation. --- MM.pas | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/MM.pas b/MM.pas index f057fc0..96b6d4d 100644 --- a/MM.pas +++ b/MM.pas @@ -168,8 +168,11 @@ var begin {GMalloc} if bytes > globalSize then begin {allocate a new pool, if needed} - globalSize := poolSize; - myhandle := NewHandle(poolSize, globalID, $C010, nil); + if bytes > poolSize then + globalSize := bytes + else + globalSize := poolSize; + myhandle := NewHandle(globalSize, globalID, $C010, nil); if ToolError <> 0 then TermError(5); globalPtr := myhandle^; end; {if} @@ -209,8 +212,11 @@ var begin {LMalloc} if bytes > localSize then begin {allocate a new pool, if needed} - localSize := poolSize; - myhandle := NewHandle(poolSize, localID, $C010, nil); + if bytes > poolSize then + localSize := bytes + else + localSize := poolSize; + myhandle := NewHandle(localSize, localID, $C010, nil); if ToolError <> 0 then TermError(5); localPtr := myhandle^; end; {if}