[fpc-pascal]Exception w/ Freemem()

Pierre Muller pierre at freepascal.org
Fri Apr 11 09:39:29 CEST 2003


These kind of problems usually are due to some memory corruption,
like writing past the end of an allocated memory block,
which can then destroy the chain of free blcoks handled 
in GetMem/FreeMem functions.

I would bet that simply calling Allocate and Deallocate 
will not generate your exception...

Try to compile your program with '-ghl' option.
(and also the RTL sources if you have them,
just use 'make OPT=-ghl' in your RTL source directory)
This might help you to find out what's is going wrong.

Unless you can give aa full source code and 
a detailed suite of operations to do to reproduce the bug
(if your program is interactive)
it will be very difficult to help you more....



At 07:32 11/04/2003, you wrote:
>W/ the following code whenever I call DeAllocate() I get the following error:
>An unhandled exception occurred at 0x0806268A :
>Invalid pointer operation
>  0x0806268A
>  0x08061FB0
>  0x0805AAF7
>  0x08065D17
>  0x08048567
>
>
>I've been able to track it to the FreeMem() line, but I don't understand why 
>its doing it..
>
>I've got the folowing code:
>
>Function    tQSurface.Allocate(iWidth, iHeight: Word): Boolean;
>Begin
>  {Check for Mem}
>  If MaxAvail > (iWidth*iHeight*SizeOf(tQPixel)) then
>  Begin
>    {$IfDef QDebug}
>      WriteDebug('Allocated(): OK!');
>    {$EndIf}
>    If Allocated then DeAllocate;
>    GetMem(fBitmap, iWidth*iHeight*SizeOf(tQPixel));
>    fWidth  := iWidth;
>    fHeight := iHeight;
>    Allocate := TRUE;
>  end
>  else
>  Begin
>    {$IfDef QDebug}
>      WriteDebug('Allocate(): Not Enough Memory');
>    {$EndIf}
>    Allocate := False;
>  End;
>end;
>
>Procedure   tQSurface.DeAllocate;
>Begin
>  If fBitmap <> nil then
>  Begin
>    FreeMem(fBitmap, fWidth*fHeight*SizeOf(tQPixel));
>  end;
>end;
>
>
>
>Thanks in advanced for any help/advice..
>_______________________________________________
>fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
>http://lists.freepascal.org/mailman/listinfo/fpc-pascal




More information about the fpc-pascal mailing list