Can XmStringFree be used to deallocate memory allocated by XtMalloc - Motif

This is a discussion on Can XmStringFree be used to deallocate memory allocated by XtMalloc - Motif ; The following code snippet produces a core dump on hpux.. XmString x; x=(XmString)XtMalloc(sizeof(char)); .. .. XmStringFree(x); .. On execution of the XmStringFree(x), the execution stops and core is dumped! why does it happen?? Is it that XmStringFree can deallocate memory ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Can XmStringFree be used to deallocate memory allocated by XtMalloc

  1. Can XmStringFree be used to deallocate memory allocated by XtMalloc

    The following code snippet produces a core dump on hpux..

    XmString x;
    x=(XmString)XtMalloc(sizeof(char));
    ..
    ..
    XmStringFree(x);
    ..

    On execution of the XmStringFree(x), the execution stops and core is
    dumped!

    why does it happen?? Is it that XmStringFree can deallocate memory
    allocated to Compound Strings only(here it is sizeof(char))??

    Sagar

  2. Re: Can XmStringFree be used to deallocate memory allocated by XtMalloc

    Sagar Balan wrote:
    > The following code snippet produces a core dump on hpux..
    >
    > XmString x;
    > x=(XmString)XtMalloc(sizeof(char));
    > .
    > .
    > XmStringFree(x);
    > .
    >
    > On execution of the XmStringFree(x), the execution stops and core is
    > dumped!
    >
    > why does it happen?? Is it that XmStringFree can deallocate memory
    > allocated to Compound Strings only(here it is sizeof(char))??
    >
    > Sagar


    XmString must be created and destroyed using Xm functions.
    For a quick fix, use this

    XmString x = XmStringCreate("my text string", XmFONTLIST_DEFAULT_TAG);

    For a more complete solution read the man pages of the
    relative functions, or this
    http://www.motifdeveloper.com/tips/tip10.html
    or even this
    http://www.ist.co.uk/motif/books/vol6A/index.html


    Best regards,

    Dusan Peterc
    http://www.arahne.si

+ Reply to Thread