Browse Source

* fixed two memleaks in chmreader. Patch based on the one in Mantis #19599 by Anton

git-svn-id: trunk@17791 -
marco 14 years ago
parent
commit
b5c4072af5
1 changed files with 10 additions and 2 deletions
  1. 10 2
      packages/chm/src/chmreader.pas

+ 10 - 2
packages/chm/src/chmreader.pas

@@ -1205,7 +1205,8 @@ begin
     begin
       sitemap.free;
       Result:=AbortAndTryTextual;
-    end;
+    end
+  else Index.Free;
 end;
 
 function TChmReader.GetTOCSitemap(ForceXML:boolean=false): TChmSiteMap;
@@ -1281,7 +1282,7 @@ begin
      Exit;
    end;
 
-   // Binary Toc Exists
+     // Binary Toc Exists
    Result := TChmSiteMap.Create(stTOC);
 
    EntryInfoOffset := NtoLE(TOC.ReadDWord);
@@ -1289,10 +1290,17 @@ begin
    EntryCount      := NtoLE(TOC.ReadDWord);
    TOPICSOffset    := NtoLE(TOC.ReadDWord);
 
+   if EntryCount <> 0 then
+     begin
+       Toc.Free;
+       Exit;
+     end;
+
    NextItem := EntryInfoOffset;
    repeat
      NextItem := AddTOCItem(Toc, NextItem, Result.Items);
    until NextItem = 0;
+   TOC.Free;
 end;
 
 function TChmReader.HasContextList: Boolean;