Simple Question

This forum is read only. No new submissions are accepted.

Questions about motif? Contact us

Submitted by leetuckert on Fri, 08/10/2001 - 19:32. Developers

I have a simple question that I probably should know the answer to; however, I don`t. So, here it is

I have the following code

XmString *listItems, *listPtr;
. some other code here.
/* allocate memory and create strings */
listPtr = listItems = (XmString *) XtCalloc (cnt, sizeof (XmString));
for (x = 0; x < cnt; x++)
*listPtr++ = XmStringCreate (data->addr->code,
data = data->next;
. Do something with the strings
/* free the memory */
for (x = 0; x < cnt; x++)
XmStringFree (listItems[x]);

XmStringFree ((XmString) listItems);

Ok. Question Do I need the last XmStringFree? I am freeing each of the elements in the for loop, but do I need to free the pointer itself? The code works either way, but I ran across a piece of code that my associated had written that was causing a problem. She had a static array of XmStrings defined and was making that final call to XmStringFree as above. On some of the interfaces, it was causing odd behavior and core dumps. My array is not static, but dynamic. So, do I need the last XmStringFree or not?


Tue, 07/03/2012 - 11:02
3 posts / 0 new
Last post
Tue, 07/03/2012 - 11:03
Tue, 07/03/2012 - 11:08