浏览代码

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

Michaël Van Canneyt 10 月之前
父节点
当前提交
cd13d5bb3a
共有 2 个文件被更改,包括 9 次插入3 次删除
  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.Free;
     FDocument:=Nil;
     FDocument:=Nil;
     end;
     end;
-  ReadXMLFile(FDocument,S);
-  if (FDocument=Nil) then
+  try
+    ReadXMLFile(FDocument,S);
+    if (FDocument=Nil) then
+      CreateEmptyDoc;
+  except
     CreateEmptyDoc;
     CreateEmptyDoc;
+  end;
   SetRootKey('HKEY_CURRENT_USER');
   SetRootKey('HKEY_CURRENT_USER');
   FDirty:=False;
   FDirty:=False;
 end;
 end;

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

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