>>>>> On Wed, 30 Jan 2002 15:58:52 +0100 (CET), "Alexander Mai" 
><[EMAIL PROTECTED]> said:

  Alexander> On Wed, 30 Jan 2002 14:48:17 -0000, Martin Simmons wrote:

  >>>>>>> On Wed, 30 Jan 2002 14:20:38 +0100 (CET), "Alexander Mai"
  >> <[EMAIL PROTECTED]> said:
  >> 
  Alexander> I think you're right.
  Alexander> Right now I'm committing some change to CVS, which is
  Alexander> not complete yet, but seems to get your example right...
  >> 
  >> Thanks.  BTW, isn't there a memory leak now?  I don't see what would free the
  >> result of XtNewString if the resource is set a second time.

  Alexander> Leak?
  Alexander> I think I introduced just the "opposite" (bogus free())
  Alexander> and tried to fix this in a second commit...
  Alexander> A new free call was added to Destroy().

True, but values before the final one are never freed (i.e. the XtNewString'd
copy of "first text" in my example).


  >> Looking at this again, it isn't clear to me why the value slot is needed at all,
  >> because the text itself is held in Text_Source.  Maybe it can simply be set to
  >> NULL by SetValues(), i.e. just used to detect when the resource is being
  >> modified?  (Possibly Xt provides a better way of doing such 'virtual'
  >> resources.)
  >> 
  >> __Martin

  Alexander> That was probably meant by some comment in the source about the
  Alexander> "obsolete value" stuff. It isn't obsolete, but that comment
  Alexander> probably indicated what you're saying.

So maybe the diff below will DTRT.  I've moved the NULLing in Initialize() so
that it gets done for all strings, otherwise an initial explicit empty string
will not work.  This diff is relative to 1.153 because the 1.154 changes don't
seem to be needed if NULL is the quiescent value of the slot.  The use of NULL
assumes that NULL isn't a valid setting for the resource: if it is valid, them
some other pointer must be used, one that is guaranteed not to be the same as
the user's string pointer).

===================================================================
rcs file: /cvsroot/lesstif/lesstif/lib/Xm/Text.c,v
retrieving revision 1.153
diff -u -r1.153 Text.c
--- Text.c      2002/01/30 13:18:38     1.153
+++ Text.c      2002/01/30 16:11:21
@@ -652,9 +652,10 @@
        Text_BottomPos(w) = Text_LineTable(w)[Text_LineCount(w)].start_pos;
        Text_Repaint(w).range[0].to = Text_BottomPos(w);
 
-       Text_Value(w) = NULL; /* amai: FIX ME! We should check for value! */
        }
 
+    Text_Value(w) = NULL; /* amai: FIX ME! We should check for value! */
+
     /* initialize default DropSite */
     import_target[0] = XmInternAtom(XtDisplay(new_w), _XA_COMPOUND_TEXT, False);
     import_target[1] = XmInternAtom(XtDisplay(new_w), _XA_TEXT, False);
@@ -696,7 +697,6 @@
     XtFree((char *)Text_Highlight(w).list);
     XtFree((char *)Text_OldHighlight(w).list);
     XtFree((char *)Text_Repaint(w).range);
-    if (Text_Value(w)) XtFree(Text_Value(w));
 
     /* amai: not sure this is necessary ...
              Check out the register calls for more info.
@@ -731,15 +731,12 @@
     if (Text_WcsValue(nw) != Text_WcsValue(ow))
     {
        XmTextSetStringWcs(new_w, Text_WcsValue(new_w));
-#ifdef HAVE_WCHAR_H
-       Text_WcsValue(nw)=XtMalloc(wcslen(Text_WcsValue(new_w))+1);
-       wcscpy(Text_WcsValue(nw), Text_WcsValue(ow));
-#endif
+       Text_WcsValue(new_w) = NULL;
        refresh_needed = True;
     } else if (Text_Value(nw) != Text_Value(ow))
     {
        XmTextSetString(new_w, Text_Value(new_w));
-       Text_Value(nw)=XtNewString(Text_Value(new_w));
+       Text_Value(nw) = NULL;
        refresh_needed = True;
     }

__Martin
_______________________________________________
Lesstif mailing list
[EMAIL PROTECTED]
https://terror.hungry.com/mailman/listinfo/lesstif

Reply via email to