View Issue Details

IDProjectCategoryView StatusLast Update
0037195FPCRTLpublic2020-06-11 18:22
ReporterChristo Crause Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilitysometimes
Status closedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037195: Heap manager doesn't free small blocks
DescriptionIn heapmgr the minimum block size allocation is capped at MinBlock in SysGetMem. In SysFreeMem the allocated block size to be freed is calculated based on an aligned size, but this is not capped at MinBlock size, hence the call to InternalFreeMem fails to locate the block to be freed.

Attached a patch to fix this. The patch is for freertos, but should probably also be applied to the embedded unit.
Tagsembedded, freertos
Fixed in Revision45633
FPCOldBugId
FPCTarget-
Attached Files

Activities

Christo Crause

2020-06-09 22:32

reporter  

heapmgr.patch (412 bytes)   
diff --git a/rtl/freertos/heapmgr.pp b/rtl/freertos/heapmgr.pp
index e0facf8048..725507d165 100644
--- a/rtl/freertos/heapmgr.pp
+++ b/rtl/freertos/heapmgr.pp
@@ -195,6 +195,8 @@ Unit heapmgr;
             exit;
           end;
         sz := Align(FindSize(addr)+SizeOf(pointer), sizeof(pointer));
+        if sz < MinBlock then
+          sz := MinBlock;
 
         InternalFreeMem(@pptruint(addr)[-1], sz);
 
heapmgr.patch (412 bytes)   

Christo Crause

2020-06-10 18:34

reporter   ~0123384

Problem also confirmed on target embedded-avr. Added patch for embedded version too. The freertos and embedded heapmgr units are identical, should probably move them to a common folder, like the rtl/common folder? This will prevent maintaining two versions.
embedded-heapmgr.patch (412 bytes)   
diff --git a/rtl/embedded/heapmgr.pp b/rtl/embedded/heapmgr.pp
index 50b597ecf6..060a9d92c1 100644
--- a/rtl/embedded/heapmgr.pp
+++ b/rtl/embedded/heapmgr.pp
@@ -195,6 +195,8 @@ Unit heapmgr;
             exit;
           end;
         sz := Align(FindSize(addr)+SizeOf(pointer), sizeof(pointer));
+        if sz < MinBlock then
+          sz := MinBlock;
 
         InternalFreeMem(@pptruint(addr)[-1], sz);
 
embedded-heapmgr.patch (412 bytes)   

Florian

2020-06-10 20:53

administrator   ~0123387

Thanks, applied.

Christo Crause

2020-06-11 18:22

reporter   ~0123397

Thanks.

Issue History

Date Modified Username Field Change
2020-06-09 22:32 Christo Crause New Issue
2020-06-09 22:32 Christo Crause File Added: heapmgr.patch
2020-06-10 18:30 Christo Crause Tag Attached: embedded
2020-06-10 18:30 Christo Crause Tag Attached: freertos
2020-06-10 18:34 Christo Crause Note Added: 0123384
2020-06-10 18:34 Christo Crause File Added: embedded-heapmgr.patch
2020-06-10 20:53 Florian Assigned To => Florian
2020-06-10 20:53 Florian Status new => resolved
2020-06-10 20:53 Florian Resolution open => fixed
2020-06-10 20:53 Florian Fixed in Version => 3.3.1
2020-06-10 20:53 Florian Fixed in Revision => 45633
2020-06-10 20:53 Florian FPCTarget => -
2020-06-10 20:53 Florian Note Added: 0123387
2020-06-11 18:22 Christo Crause Status resolved => closed
2020-06-11 18:22 Christo Crause Note Added: 0123397