Просмотр исходного кода

+ Win32 SEH: to avoid memory leaks, it is necessary to free exception object for non-FPC exceptions on re-raise (it will be re-created by next exception handler).

git-svn-id: trunk@26241 -
sergei 11 лет назад
Родитель
Сommit
b82b6da493
2 измененных файлов с 11 добавлено и 0 удалено
  1. 1 0
      rtl/inc/objpash.inc
  2. 10 0
      rtl/win32/seh32.inc

+ 1 - 0
rtl/inc/objpash.inc

@@ -335,6 +335,7 @@
          Frames     : PCodePointer;
 {$ifdef FPC_USE_WIN32_SEH}
          SEHFrame   : Pointer;
+         ExceptRec  : Pointer;
          ReraiseBuf : jmp_buf;
 {$endif FPC_USE_WIN32_SEH}
        end;

+ 10 - 0
rtl/win32/seh32.inc

@@ -75,6 +75,15 @@ var
 begin
   hp:=ExceptObjectStack;
   ExceptObjectStack:=hp^.next;
+  { Since we're going to 'reraise' the original OS exception (or, more exactly, pretend
+    it wasn't handled), we must revert action of CommonHandler. }
+  if TExceptionRecord(hp^.ExceptRec^).ExceptionCode<>FPC_EXCEPTION_CODE then
+  begin
+    if assigned(hp^.frames) then
+      freemem(hp^.frames);
+    if hp^.refcount=0 then
+      hp^.FObject.Free;
+  end;
   TSEHFrame(hp^.SEHFrame^).Addr:=@NullHandler;
   longjmp(hp^.ReraiseBuf,1);
 end;
@@ -224,6 +233,7 @@ begin
 
   Exc.Refcount:=0;
   Exc.SEHFrame:=@frame;
+  Exc.ExceptRec:=@rec;
   { link to ExceptObjectStack }
   Exc.Next:=ExceptObjectStack;
   ExceptObjectStack:=@Exc;