At 16:24 2002-10-8 +0800, you wrote:
>Hi.
>
>I have encountered the Ptr problem where there is a pointer to char
>pointer, I allocate a MemPtrNew to the pointer to do some manipulation.
>After using it and would like to free it in the StopApplication, it give me
>an error where the pointer i free was an unallocated chunk. If i didn't
>free it, it is another error where there is an unfreed chunk when exiting
>the application.
>
>The snippet code is in local form.
>
>Char **title;
>FldPtr field = (FldPtr) GetObjectPtr(TextField);
>
>Char *text = FldGetTextPtr (field);
>
>*title = (Char*)MemPtrNew(StrLen(text)+1);

You do realize that by declaring title as a char **, and dereferencing it 
here, you're accessing random memory, since you're trying to modify the 
character pointer to which the uninitialized title points?

Just say "char *title", and then use title directly, rather than doing the 
incorrect double pointer.

>StrCopy(*title, text);

This would work, if you were just using title as a char *, not a char **.

>Whenever i don't want to use it anymore, so i have to free the chunk in
>StopApp:
>
>if(*title!=NULL)
>   MemPtrFree(*title) ;        //It give me an error that the chunk has not
>been allocated.
>                       if i don't free it, it give me another error as
>unfreed chunk has encoutered.
>
>where was i wrong? Could somebody guide me? Thank you in advance!

-- 
Ben Combee <[EMAIL PROTECTED]>
CodeWarrior for Palm OS technical lead
Palm OS programming help @ www.palmoswerks.com


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to