+ 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 -
This commit is contained in:
sergei 2013-12-16 14:47:26 +00:00
parent ee152cde6a
commit b82b6da493
2 changed files with 11 additions and 0 deletions

View File

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

View File

@ -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;