From 2d2fb7b3b8d9b14bec1b2629ba7473758c21855d Mon Sep 17 00:00:00 2001 From: tobigun Date: Thu, 23 Jul 2009 20:24:03 +0000 Subject: reset all ref-counted fields before usage of FillChar() to avoid memory leaks git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/experimental@1908 b956fd51-792f-4845-bead-9b4dfca2ff2c --- unicode/src/base/UCovers.pas | 3 +++ unicode/src/base/UFilesystem.pas | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'unicode/src') diff --git a/unicode/src/base/UCovers.pas b/unicode/src/base/UCovers.pas index 0dbe672a..6c7c9e48 100644 --- a/unicode/src/base/UCovers.pas +++ b/unicode/src/base/UCovers.pas @@ -385,6 +385,9 @@ begin end else begin + // FillChar() does not decrement the ref-count of ref-counted fields + // -> reset Name field manually + Result.Name := nil; FillChar(Result, SizeOf(TTexture), 0); end; except on E: Exception do diff --git a/unicode/src/base/UFilesystem.pas b/unicode/src/base/UFilesystem.pas index a28b1f39..d4972df5 100644 --- a/unicode/src/base/UFilesystem.pas +++ b/unicode/src/base/UFilesystem.pas @@ -665,7 +665,11 @@ function TFileIterator.Next(): TFileInfo; begin if (not fHasNext) then begin - FillChar(Result, SizeOf(Result), 0); + // Note: do not use FillChar() on records with ref-counted fields + Result.Time := 0; + Result.Size := 0; + Result.Attr := 0; + Result.Name := nil; Exit; end; -- cgit v1.2.3