gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gm2] Re: double free or corruption with pointers


From: Martin Kalbfuß
Subject: [Gm2] Re: double free or corruption with pointers
Date: Sun, 01 Aug 2010 12:05:34 +0200

Sorry,

wrong program. Here is the correct one.

MODULE test2;

IMPORT SYSTEM, SWholeIO, STextIO;
FROM Storage IMPORT ALLOCATE, DEALLOCATE;

TYPE DynArray = POINTER TO INTEGER;
VAR  myArray    : DynArray;
     elementPtr : DynArray;
BEGIN
     NEW(myArray, 6, 6);
     elementPtr := SYSTEM.ADDADR(myArray, 2*5+3);
     elementPtr^ := 5;
     SWholeIO.WriteInt(elementPtr^, 1); STextIO.WriteLn();
     DISPOSE(myArray);
END test2.

Maybe I'm wrong about pointers. Isn't there a better way of using
dynamic arrays? It's really a pain.

Am Sonntag, den 01.08.2010, 11:55 +0200 schrieb Martin Kalbfuß:
> Hi! The following program ends up with a double free corruption. I'm not
> sure how this can happen. Anything wrong with my code?
> 
> MODULE test2;
> 
> IMPORT SYSTEM, SWholeIO, STextIO;
> FROM Storage IMPORT ALLOCATE, DEALLOCATE;
> 
> TYPE DynArray = POINTER TO INTEGER;
> VAR  myArray : DynArray;
>      elementPtr : DynArray;
> BEGIN
>      NEW(myArray, 6, 6);
>      elementPtr := SYSTEM.ADDADR(myArray, 2*5+3);
>      SWholeIO.WriteInt(elementPtr^, 1); STextIO.WriteLn();
>      DISPOSE(myArray);
> END test2.
> 
> 
> Thanks,
> Martin





reply via email to

[Prev in Thread] Current Thread [Next in Thread]