Browse Source

* Patch from Iluha Companets to avoid crash when registry XML file is empty. Fixes issue #40912

Michaël Van Canneyt 10 months ago
parent
commit
cd13d5bb3a
2 changed files with 9 additions and 3 deletions
  1. 6 2
      packages/fcl-registry/src/xmlreg.pp
  2. 3 1
      packages/fcl-registry/src/xregreg.inc

+ 6 - 2
packages/fcl-registry/src/xmlreg.pp

@@ -603,9 +603,13 @@ begin
     FDocument.Free;
     FDocument:=Nil;
     end;
-  ReadXMLFile(FDocument,S);
-  if (FDocument=Nil) then
+  try
+    ReadXMLFile(FDocument,S);
+    if (FDocument=Nil) then
+      CreateEmptyDoc;
+  except
     CreateEmptyDoc;
+  end;
   SetRootKey('HKEY_CURRENT_USER');
   FDirty:=False;
 end;

+ 3 - 1
packages/fcl-registry/src/xregreg.inc

@@ -190,8 +190,10 @@ procedure TRegistry.SysRegFree;
 
 begin
   if Assigned(FSysData) then
+  begin
     TXMLRegistry(FSysData).Flush;
-  TXMLRegistryInstance.FreeXMLRegistry(TXMLRegistry(FSysData));
+    TXMLRegistryInstance.FreeXMLRegistry(TXMLRegistry(FSysData));
+  end;
 end;
 
 function TRegistry.SysCreateKey(Key: UnicodeString): Boolean;