View Issue Details

IDProjectCategoryView StatusLast Update
0036052FPCFCLpublic2020-01-14 11:16
ReporterBernd Rummel Assigned ToOndrej Pokorny  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0036052: Error when TIniFile is released and Encoding is set
Descriptionprocedure openIni;
var
  ini: TIniFile;
begin
  ini := TIniFile.Create('test.ini',TMBCSEncoding.Create(850)); // test.ini must exist
  ini.Free; // => exception
end;
Additional Informationinifiles.pp
procedure TIniFile.ReadIniValues;
var
  slLines: TStringList;
begin
  FSectionList.Clear;

  if FileExists(FFileName) then
  begin
    slLines := TStringList.Create;
    try
      // read the ini file values
      if FEncoding=nil then
        slLines.LoadFromFile(FFileName)
      else
      begin
        slLines.DefaultEncoding := FEncoding; // slLines clone Encoding
        slLines.LoadFromFile(FFileName, nil);
        if FEncoding <> slLines.Encoding then
        begin
          if FOwnsEncoding then
            FEncoding.Free;
          FEncoding := slLines.Encoding; // Copy Encoding
          FOwnsEncoding := not TEncoding.IsStandardEncoding(FEncoding);
        end;
      end;
      FillSectionList(slLines); // slLines free Encoding => Self.FEncoding is freed => Exception on destroy
    finally
      slLines.Free;
    end;
  end;
end;
TagsNo tags attached.
Fixed in Revision42932, 43938
FPCOldBugId
FPCTarget3.2.0
Attached Files

Activities

Bernd Rummel

2019-09-06 21:00

reporter  

inifiles.pp.patch (597 bytes)   
Index: inifiles.pp
===================================================================
--- inifiles.pp	(Revision 42922)
+++ inifiles.pp	(Arbeitskopie)
@@ -1384,13 +1384,6 @@
       begin
         slLines.DefaultEncoding := FEncoding;
         slLines.LoadFromFile(FFileName, nil);
-        if FEncoding <> slLines.Encoding then
-        begin
-          if FOwnsEncoding then
-            FEncoding.Free;
-          FEncoding := slLines.Encoding;
-          FOwnsEncoding := not TEncoding.IsStandardEncoding(FEncoding);
-        end;
       end;
       FillSectionList(slLines);
     finally
inifiles.pp.patch (597 bytes)   

Michael Van Canneyt

2019-09-07 16:02

administrator   ~0117970

Resolved as proposed, thanks for the patch!

Ondrej Pokorny

2020-01-14 09:36

developer   ~0120424

This needs to be rewritten.

Ondrej Pokorny

2020-01-14 11:16

developer   ~0120425

The patch was wrong - it removed Encoding preservation of the INI file entirely.

Fixed with Encoding preservation, please test and close if OK.

Issue History

Date Modified Username Field Change
2019-09-06 21:00 Bernd Rummel New Issue
2019-09-06 21:00 Bernd Rummel File Added: inifiles.pp.patch
2019-09-07 16:02 Michael Van Canneyt Assigned To => Michael Van Canneyt
2019-09-07 16:02 Michael Van Canneyt Status new => resolved
2019-09-07 16:02 Michael Van Canneyt Resolution open => fixed
2019-09-07 16:02 Michael Van Canneyt Fixed in Version => 3.3.1
2019-09-07 16:02 Michael Van Canneyt Fixed in Revision => 42932
2019-09-07 16:02 Michael Van Canneyt FPCTarget => 3.2.0
2019-09-07 16:02 Michael Van Canneyt Note Added: 0117970
2020-01-14 09:36 Ondrej Pokorny Assigned To Michael Van Canneyt => Ondrej Pokorny
2020-01-14 09:36 Ondrej Pokorny Status resolved => feedback
2020-01-14 09:36 Ondrej Pokorny Resolution fixed => reopened
2020-01-14 09:36 Ondrej Pokorny Note Added: 0120424
2020-01-14 11:16 Ondrej Pokorny Status feedback => resolved
2020-01-14 11:16 Ondrej Pokorny Resolution reopened => fixed
2020-01-14 11:16 Ondrej Pokorny Fixed in Revision 42932 => 42932, 43938
2020-01-14 11:16 Ondrej Pokorny Note Added: 0120425