OSDN Git Service

FMOを調べるごとにリソースリークしていた可能性を潰す
authorC.Ponapalt <ponapalt@shillest.net>
Thu, 11 Mar 2004 16:51:29 +0000 (16:51 +0000)
committerC.Ponapalt <ponapalt@shillest.net>
Thu, 11 Mar 2004 16:51:29 +0000 (16:51 +0000)
sakurasuite/SakuraSeeker.pas

index a65d68f..33014d3 100644 (file)
@@ -209,7 +209,7 @@ end;
 
 procedure TSakuraSeeker.BeginDetectOne(const Target: String);
 var MappingHandle, Mutex: THandle;
-    P: pointer;
+    P, PSaved: pointer;
     SourceStr, ID, Entry, Data: String;
     Size: integer;
     Strs: TStringList;
@@ -217,8 +217,10 @@ var MappingHandle, Mutex: THandle;
     i, j: integer;
 begin
   //\83t\83@\83C\83\8b\83}\83b\83s\83\93\83O\83I\83u\83W\83F\83N\83g\82Ì\8eæ\93¾
-  P := nil;
+  PSaved := nil;
   Strs := nil;
+  MappingHandle := 0;
+  
   Mutex := GetMutex(GetMutexName(Target));
   if Mutex = 0 then
     raise ESakuraSeekerError.Create('Mutex\83n\83\93\83h\83\8b\82ð\8eæ\93¾\82Å\82«\82Ü\82¹\82ñ\82Å\82µ\82½');
@@ -230,7 +232,8 @@ begin
       if MappingHandle = 0 then begin
         SourceStr := '';
       end else begin
-        P := MapViewOfFile(MappingHandle, FILE_MAP_READ, 0, 0, 0);
+        PSaved := MapViewOfFile(MappingHandle, FILE_MAP_READ, 0, 0, 0);
+        P := PSaved;
         if P <> nil then begin
           CopyMemory(@Size, P, SizeOf(integer));
           Inc(PChar(P), SizeOf(integer));
@@ -241,10 +244,10 @@ begin
       end;
     finally
       //\83I\83u\83W\83F\83N\83g\82Ì\94j\8aü
-      if P <> nil then UnmapViewOfFile(P);
-      if MappingHandle <> 0 then CloseHandle(MappingHandle);
+      if PSaved <> nil then UnmapViewOfFile(PSaved);
     end;
   finally
+    if MappingHandle <> 0 then CloseHandle(MappingHandle);
     ReleaseMutex(Mutex);
   end;