View Issue Details

IDProjectCategoryView StatusLast Update
0036529FPCCompilerpublic2020-01-06 17:22
ReporterCyrax Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformLinux x86_64OSArch 
Product Version3.3.1 
Summary0036529: lineinfo units, valgrind and heaptrace unit woes : Access violation occurs when freeing memory space belonging to another
Descriptionlineinfo units uses dynamic arrays (especially lnfodwrf) during their operation. Due to this, when cmem unit is added to mix (when user wants to use valgrind features), its early finalization related to lineinfo units will cause memory deallocation bugs to happen. This is because old memory manager tries to release memory belong to another one.

Thus move cmem unit before line info units and make that when user uses heaptrace with valgrind, do not add heaptrace unit to mix, too.
Tagspatch
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Cyrax

2020-01-06 17:17

reporter  

pmodules.pas.diff (1,275 bytes)   
diff --git a/compiler/pmodules.pas b/compiler/pmodules.pas
index cc5e0afc4f..e75d7f8185 100644
--- a/compiler/pmodules.pas
+++ b/compiler/pmodules.pas
@@ -325,8 +325,11 @@ implementation
         if not(current_module.is_unit) then
          begin
            { Heaptrc unit, load heaptrace before any other units especially objpas }
-           if (cs_use_heaptrc in current_settings.globalswitches) then
+           if (cs_use_heaptrc in current_settings.globalswitches) and not (cs_gdb_valgrind in current_settings.globalswitches) then
              AddUnit('heaptrc');
+           { Valgrind requires c memory manager }
+           if (cs_gdb_valgrind in current_settings.globalswitches) then
+             AddUnit('cmem');
            { Lineinfo unit }
            if (cs_use_lineinfo in current_settings.globalswitches) then begin
              case target_dbg.id of
@@ -338,9 +341,6 @@ implementation
                  AddUnit('lnfodwrf');
              end;
            end;
-           { Valgrind requires c memory manager }
-           if (cs_gdb_valgrind in current_settings.globalswitches) then
-             AddUnit('cmem');
 {$ifdef cpufpemu}
            { Floating point emulation unit?
              softfpu must be in the system unit anyways (FK)
-- 
2.24.1
pmodules.pas.diff (1,275 bytes)   

Florian

2020-01-06 17:22

administrator   ~0120235

I think silently disabling heaptrc when valgrind is used, is not an option. It should stop with a fatal error if this is really needed.

Issue History

Date Modified Username Field Change
2020-01-06 17:17 Cyrax New Issue
2020-01-06 17:17 Cyrax File Added: pmodules.pas.diff
2020-01-06 17:18 Cyrax Tag Attached: patch
2020-01-06 17:22 Florian Note Added: 0120235