At 04:16 AM 7/28/2006, you wrote:
Subject: Re: Memory Leak
From: cbruner <[EMAIL PROTECTED]>
Date: Thu, 27 Jul 2006 14:15:22 -0400
X-Message-Number: 11
Helmut A. Bender wrote:
> Am Donnerstag, 27. Juli 2006 15:40 schrieb Micky MeNeZeS:
>
>> I have got following code.
>> [...]
>>
>
> It seems you don't initialize the buffer you create. So the check in
> StringCopy
>
>> if (StrLen(aBuffer) == 0)
>>
> won't work, since StrLen will get a random value. Set the first
byte of the
> buffer to '\0' at the beginning.
>
> The rest seems quite nice to me...
>
>
Good eyes. Also as a matter of style, you might want to keep a pointer
showing where the string was last appended to. Then pass the pointer to
your function for appending strings. Then it doesn't have to look
through the whole buffer each time it needs to append onto the end of it.
You also have a potential landmine sitting in your code. You assign
memory to the handle, then go ahead and use that memory in the hope
that your allocation succeeded.
So perhaps your code should be
Err SendDefaultPage(int fp)
{
MemHandle h;
Err errno = errNone;
UInt16 i=0;
h = MemHandleNew (bufferSize);
if (!h) return memErrNotEnoughSpace;
...
Roger Stringer
Marietta Systems, Inc. (www.rf-tp.com)
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/