View Issue Details

IDProjectCategoryView StatusLast Update
0036052FPCFCLpublic2019-09-07 16:02
ReporterBernd RummelAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.3.1Product Buildsvn trunk revision 4291 
Target VersionFixed 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
FPCOldBugId
FPCTarget3.2.0
Attached Files
  • 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)

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!

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