I have been using heaptrc to locate memory leaks as I develop a fairly large suite of software. I now need to link to some software written in C (compiled with gcc); the C is fairly old, tightly written and riddled with dynamic memory allocation. Normally I would just translate the C to Pascal to keep everything simple, but reading through this C code I decided that life was too short ...
For convenience I have written a unit as a wrapper, and this unit LINKLIBs to the 'c' and 'm' C libraries and LINKs to the C object file. In test programs this works well without any use of CMem.
What is passed to the C code is a Pascal record that has a number of dynamically allocated arrays as fields, and a couple of similar records which the C code will use by dynamically allocating (malloc) memory as the fields' arrays and which are then passed back to the Pascal code to use. The C links happily with the Pascal and for simple cases runs fine, but it doesn't take much complexity before the whole thing collapses at random points with memory errors. For example:
Marked memory at $00007FD0F03BFF30 invalid
Wrong signature $1F4AE121 instead of 5998D445
I assume (given the warning on the Wiki page
https://wiki.freepascal.org/heaptrc) that there is a clash between heaptrc (as memory manager) and the C memory manager used by the C code. I also assume that heaptrc is incompatible with the unit CMem.
Are my assumptions correct? Is there any way for heaptrc and C code to cohabit, or are they completely incompatible so that it is either use heaptrc or link to C code (but not both)?