Submitted by leetuckert on Fri, 08/10/2001 - 19:26.
Hello
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,
XmSTRING_DEFAULT_CHARSET);
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?
Thanks!