Menu

#63 FastMM doesn't detect double call to FreeMem

v1.0 (example)
open
nobody
None
5
2013-11-14
2013-11-12
Igor
No

The code below produces AV instead of report about double call to FreeMem.

    var
      P: Pointer;
    begin
      GetMem(P, 50);
      FreeMem(P);
      FreeMem(P);
    end;

Discussion

  • Pierre le Riche

    Pierre le Riche - 2013-11-14

    Hi Igor,

    In normal mode (i.e. not "FullDebugMode"), the address space surrounding a block may be released to the operating system when a block is freed, so it is not always possible for FastMM to catch such a double free "gracefully". That said, double frees should almost always crash your application (either through above A/V or another exception raised by FastMM) so the end result is the same.

    Best regards,
    Pierre

     
  • Igor

    Igor - 2013-11-14

    Here is exception log in FullDebugMode:


    Date: 14 Nov 2013 09:51:02
    Address: 00408D96
    ClassName: EAccessViolation
    Message: Access violation at address 00408D96 in module 'BatPost.exe'. Read of address 00000002
    IsOSException: 1
    Modules:
    00400000 20131114075057 C:\ritserver\EXE\BatPost.exe
    Stack:
    00408D96 [00400000][FastMM4][FastMM4.GetAvailableSpaceInBlock][3310]
    0040AD1A [00400000][FastMM4][FastMM4.CheckBlockBeforeFreeOrRealloc][8810]
    0040AD95 [00400000][FastMM4][FastMM4.DebugFreeMem][8857]
    004030B4 [00400000][System][System.@FreeMem][2699]
    005507C5 [00400000][BatPost][BatPost.BatPost][436]


    AllocatedByRoutine can be used in CheckBlockBeforeFreeOrRealloc to determine that memory block is already freed before calling GetAvailableSpaceInBlock.

     

    Last edit: Igor 2013-11-14

Log in to post a comment.

MongoDB Logo MongoDB