Discussion:
Memory leak?
(too old to reply)
Alien
2007-03-31 18:37:47 UTC
Permalink
Raw Message
Using Delphi7

I am using FastMM4 and it shows thet I am getting a memory leak with the code below.
What can I do to fix it with your help that is.

procedure TProject1.GetMyPostedMid; ///
var
P, Q, Temp: PChar;
XFace: array[0..1024] of Char;
begin
P := ReadWrite.GetText; // ReadWrite is a TStringList
Q := StrNew(P);
begin
P := StrPos(Q, 'Message-ID: ');
if P <> nil then
P := P + 12;
Temp := StrPos(P, #13#10);
Temp^ := #0;
StrLCopy(XFace, P, SizeOf(XFace) - 1);
Memo1.Lines.Add(Trim(XFace)); // Adds the Message-ID: <***@watever> to Memo1
end;
end;
--
-A-l-i-e-n-
Vertuas
2007-04-15 21:24:07 UTC
Permalink
Raw Message
Post by Alien
Using Delphi7
I am using FastMM4 and it shows thet I am getting a memory leak with the code below.
What can I do to fix it with your help that is.
procedure TProject1.GetMyPostedMid; ///
var
P, Q, Temp: PChar;
XFace: array[0..1024] of Char;
begin
P := ReadWrite.GetText; // ReadWrite is a TStringList
Q := StrNew(P);
begin
P := StrPos(Q, 'Message-ID: ');
if P <> nil then
P := P + 12;
Temp := StrPos(P, #13#10);
Temp^ := #0;
StrLCopy(XFace, P, SizeOf(XFace) - 1);
end;
end;
--
-A-l-i-e-n-
Q:=StrNew(p);

this line allocates memory to create a new instance of P

you need to free this memory.

Loading...