Look what I've found today:
Look what I've found today:
procedure DoSmth;
var
s: string;
begin
// snip
Finalize(s);
ZeroMemory(@s, SizeOf(s));
// snip
end;
procedure DoSmth;
var
s: string;
begin
// snip
Finalize(s);
ZeroMemory(@s, SizeOf(s));
// snip
end;
This is an obfuscated version of
ReplyDeletes := '';
and the ZeroMemory() is just useless, since Finalize(s) did already set the s pointer to nil.
It might be left from s being a short string and was meant to be a security measure so the old value of s doesn't stay in memory.
ReplyDeleteThomas Mueller AFAIR Finalize() did not exist with original shortstrings, only getmem/freemem/new/dispose/mark/release did exist at that time, for records allocation on the heap - see https://archive.org/stream/bitsavers_borlandturVersion7.0LanguageGuide1992_10480217/Turbo_Pascal_Version_7.0_Language_Guide_1992#page/n1/mode/2up - and under newer version the compiler, it is a "no op", reported as "Hint: Expression needs no Initialize/Finalize".
ReplyDeleteOne of the first versions of Delphi leaked every local string variable. You had to end every procedure/method with s := ''; to avoid the leak. It was fixed later in a revision, but we had to release software (>1M LOC) before the fix. I still find remnants of this in our code.
ReplyDeleteAhh, that explains why some of the old TurboPower libraries did that. I wondered what was going on with that.
ReplyDelete