Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!twg.com!david From: david@twg.com (David S. Herron) Newsgroups: comp.windows.x Subject: Re: more on XmString problem Keywords: Motif 1.1, XmStringCreateLtoR, XmStringGetLtoR, UIL Message-ID: <8861@gollum.twg.com> Date: 25 Apr 91 17:39:35 GMT References: <95655@lll-winken.LLNL.GOV> Organization: The Wollongong Group, Palo Alto, CA Lines: 39 In article <95655@lll-winken.LLNL.GOV> chapman@lll-crg.llnl.gov (Carol Chapman) writes: > XtSetArg(al[ac],XmNlabelString, > XmStringCreate("hello",XmSTRING_DEFAULT_CHARSET)); ac++; This is a bad idea because it creates a memory leak. XmStringCreate() returns an XtMalloc()d object which is then duplicated into another XtMalloc()d object inside the Motif library. The one returned by XmStringCreate() is then abandoned .. XmString string = XmStringCreate("hello",XmSTRING_DEFAULT_CHARSET); XtSetArg(al[ac],XmNlabelString, string); ac++; ...XtSetValues()... XmStringFree(string); Is much better. >char* get_label(Widget id) [num = 0;] > XtSetArg(wargs[num], XmNlabelString, &label_str); num++; > XtGetValues(id, wargs, num); > > /* Pull the character string out of the XmString */ > XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label); > > /* Free string and make sure we free the pixmap (if there was one) */ > XmStringFree(label_str); Is exactly what my code does (though I use XmStringCreateLtoR()) and it just works. Platforms: SysVr3.2.2/386 & Motif 1.0, SunOS 4.0.2 on Sun 386i with Motif 1.1.1, and SunOS 4.1.1 on Sun3 with Motif 1.1.1. David -- <- David Herron, an MMDF & WIN/MHS guy, <- Formerly: David Herron -- NonResident E-Mail Hack <- <- "MS-DOS? Where we're going we don't need MS-DOS." --Back To The Future