Simplified example:
var
Outputfile: unias_final_file;
tmp: Pointer;
begin
//initialize some fields
OutPutFile.SectionCount := 1;
SetLength(OutPutFile.SectionContent,1);
SetLength(OutputFile.SectionSize,1);
OutputFile.SectionSize[0] := 256;
writeln('1');
writeln(OutputFile.SectionSize[OutputFile.SectionCount-1]);
tmp := getmem(OutputFile.SectionSize[OutputFile.SectionCount-1]);
OutputFile.SectionContent[OutputFile.SectionCount-1] := tmp;
writeln('2');
FreeMem(OutputFile.SectionContent[OutputFile.SectionCount-1]);
end.
Outputs:
C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test
1
256
2
Heap dump by heaptrc unit of C:\Users\Bart\LazarusProjecten\ConsoleProjecten\test.exe
3 memory blocks allocated : 280/288
3 memory blocks freed : 280/288
0 unfreed memory blocks : 0
True heap size : 131072 (112 used in System startup)
True free heap : 130960So, you need to check the value of each variable you use in your code to see if anything is not what it is supposed to be.
B.t.w. your project (as attached in your first post) does not compile: unihash.pas(17,10) Error: Forward declaration not solved "unihash_generate_value(AnsiString):QWord;"
This is because you define:
function unihash_generate_value(str:string):qword;
....
function unihash_generate_value(str:string):SizeUint;
begin
if(str='') then exit(0);
Result:=unihash_city_hash_64(Pointer(str),length(str));
end;
On 32-bit SizeUInt<>QWord
(Also there are some illegal typecastst to SizeInt (when compiled for 32-bit).)
If I fix this, compilation succeeds.
When built for 64-bit Windows the program crashes in a different place:
C:\Users\Bart\LazarusProjecten\bugs\forum\unias\unias>unias
An unhandled exception occurred at $0000000100098872:
EIntOverflow: Arithmetic overflow
$0000000100098872 unihash_hash_length_0_to_16, line 75 of unihash.pas
$0000000100099021 unihash_city_hash_64, line 145 of unihash.pas
$00000001000994F0 unihash_generate_value, line 175 of unihash.pas
$000000010003DF8A unias_authority_add, line 930 of uniasinfo.pas
$0000000100041AF9 unias_initialize_architecture, line 1365 of uniasinfo.pas
$000000010000183D $main, line 9 of unias.lpr
$0000000100001A16
$00000001000118C0
$00000001000017A0
$00007FFB9C22E8D7
$00007FFB9CF8C40CSo, at this point I give up.
If this program is NOT supposed to do anything under Windows, then insert a compiler message like {$fatal this program is only supposed to compile under xxx}.
Bart
PS. Some whitespace (empty lines) between procedures would increase readability.
And a single procedure of 461 lines is not helping there as well.