A possible Solution to the potential error in astrings might be to use interlockedexchange (for pointers)
Attempt:
Procedure fpc_AnsiStr_Assign (Var DestS : Pointer;S2 : Pointer);[Public,Alias:'FPC_ANSISTR_ASSIGN']; compilerproc;
{
Assigns S2 to S1 (S1:=S2), taking in account reference counts.
}
begin
if DestS=S2 then
exit;
If S2nil then
If PAnsiRec(S2-FirstOff)^.Ref>0 then
inclocked(PAnsiRec(S2-FirstOff)^.ref);
{ Decrease the reference count on the old S1 }
// Changed part
S2:=InterLockedExchangePointer(DestS,S2);
fpc_ansistr_decr_ref (S2);
{ And finally, have DestS pointing to S2 (or its copy) }
// Removed DestS:=S2;
end;That would give us a "Nil" the second time, which would be ignored by decr_ref then.
