Link to home
Start Free TrialLog in
Avatar of shawn857
shawn857

asked on

"Freemem" statement now gives "Invalid Pointer Operation". Used to work OK.

Hello Experts... I have a routine which would read a "chunk" of bytes from a file using a stream, do a bit of processing, then write that chunk to an output stream.. and repeat this till nothing left to read. Before the read I have these statements:

    Chunksize := 2048000;
    GetMem(CopyBuffer, ChunkSize); // CopyBuffer is defined as a PChar

And I do the read as such:

ibytesOK:=InfileStream.Read(CopyBuffer^, ChunkSize);

At the end when cleaning things up and closing files, I have this statement:

FreeMem(CopyBuffer, Chunksize);


This all used to work fine, until I just added some code that steps through the CopyBuffer a bit, looking for a #13 character:

while CopyBuffer^ <> #13 do  
       Inc(CopyBuffer);

Now when I run it, it crashes on the FreeMem(CopyBuffer, Chunksize); statement giving "Invalid Pointer Operation". Any idea how to remedy this, anyone?

Thanks!
    Shawn
ASKER CERTIFIED SOLUTION
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shawn857
shawn857

ASKER

ahh you are right Sinisa... thank you my friend!

Cheers
   Shawn