After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 126813 - GOK doesn't quit
GOK doesn't quit
Status: RESOLVED FIXED
Product: gok
Classification: Deprecated
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: David Bolter
David Bolter
Depends on:
Blocks:
 
 
Reported: 2003-11-12 14:57 UTC by david.hawthorne
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
a proposed fix. (676 bytes, patch)
2003-11-17 15:00 UTC, David Bolter
none Details | Review
alternate patch (3.58 KB, patch)
2003-11-17 15:26 UTC, bill.haneman
none Details | Review
revised patch which removes leak and another pre-existing leak of similar origin (1.76 KB, patch)
2003-11-17 16:32 UTC, bill.haneman
none Details | Review
final patch (1.78 KB, patch)
2003-11-17 16:35 UTC, bill.haneman
none Details | Review

Description david.hawthorne 2003-11-12 14:57:02 UTC
using a gnome-2.4 build from 12 Nov 2003

-launch GOK
-choose 'GOK' -> 'Quit GOK' -> 'Really Quit!'

.GOK's 'Really Quit!' button flashes but GOK does not quit..
Comment 1 David Bolter 2003-11-12 15:04:41 UTC
Something has gone wrong ;-)

I've been looking into this (distractedly) for a few days.  Do you
have any console output?  Note gok has configure/autogen options
--enable-logging-normal and --enable-logging-exceptional (which can be
used together).

Does it only happen if you have been using accessible applications
with gok?
Comment 2 David Bolter 2003-11-12 15:15:23 UTC
DH, scratch that, I am seeing the bug you describe and it is not the
same behaviour I was talking about -- will investigate shortly.
Comment 3 David Bolter 2003-11-12 15:44:48 UTC
I think this has to do with the need to a g_strstrip()...

Bill, where are we with the problem of spaces in our xml?  Shall we
perform the g_strstrip early and once -- when we read the keyboards?

(david heads to a meeting :-( )
Comment 4 bill.haneman 2003-11-13 16:09:29 UTC
daniel:  is there a simple way we can ask libxml2 to strip all
leading/trailing whitespace?

I know we can specify 'preserve', which won't strip, and 'default'
(which is whatever-the-parser-wants to do), but is there a simple
piece of API we can use to ask libxml2's parser or reader to always strip?

thanks
Comment 5 Daniel Veillard 2003-11-13 17:17:54 UTC
I think the answer is no.

In XML all white space within content are considered significant
so XML parser really should not remove white spaces, except
in some case in attributes where this is defined by the spec.
Moreover the notion of "stripping" usually means removing
leading and ending whitespaces of a string of character, it's
really not proper to do that at the parser level because this
is really a change that require application specific knowledge.

Daniel 
Comment 6 David Bolter 2003-11-17 15:00:15 UTC
Created attachment 21532 [details] [review]
a proposed fix.
Comment 7 bill.haneman 2003-11-17 15:24:19 UTC
David: I think we should do the strip more generally.  I attach an
alternate patch
Comment 8 bill.haneman 2003-11-17 15:26:44 UTC
Created attachment 21535 [details] [review]
alternate patch
Comment 9 bill.haneman 2003-11-17 15:28:39 UTC
David:  sorry to step on toes here.  Go ahead and apply the alternate
patch if you want, or I will.

If I've missed something here and the alternate isn't better, let me
know.  thanks
Comment 10 bill.haneman 2003-11-17 15:32:34 UTC
previous patch accidentally includes talking-gok stuff, please ignore
that part.

The relevant part of the patch is replacing 
the third param to gok_output_new() at the end of
gok_output_new_from_xml() with 

g_strstrip (xmlNodeGetContent (pNode)), 

[instead of just passing the result of xmlNodeGetContent directly into
gok_output_new()].
Comment 11 David Bolter 2003-11-17 15:35:48 UTC
I had considered that but I am a bit worried that it might break
something...  for example if we added arguments to the commands in
launcher.kbd, would this break?
Comment 12 Daniel Veillard 2003-11-17 15:43:52 UTC
Without even looking at the context,
  g_strstrip (xmlNodeGetContent (pNode))
is absolutely and 100% garanteed to leak memory :-(
http://xmlsoft.org/html/libxml-tree.html#xmlNodeGetContent
  
Daniel
Comment 13 David Bolter 2003-11-17 15:47:04 UTC
g_strstrip doesn't copy the string?  yoikes.
Comment 14 bill.haneman 2003-11-17 16:19:16 UTC
g_strstrip() does copy, but then there's no way to free the
xmlNodeGetContent value (which is also allocated). thanks DV.
Will send revised patch.  Note that g_strstrip only strips leading and
trailing whitespace, which is exactly what we need i.e. what we cannot
count on from the XML and intltool processes.
Comment 15 bill.haneman 2003-11-17 16:32:18 UTC
Created attachment 21539 [details] [review]
revised patch which removes leak and another pre-existing leak of similar origin
Comment 16 bill.haneman 2003-11-17 16:35:37 UTC
Created attachment 21542 [details] [review]
final patch
Comment 17 bill.haneman 2003-11-17 16:47:37 UTC
fixed in CVS.  Thanks DV for catching the really stupid mistake ;-)
Comment 18 David Bolter 2003-11-17 16:56:11 UTC
When you do this:

nodeValue = xmlNodeGetContent (pNodeKeyChild);
stringval = (nodeValue != NULL) ? g_strstrip (nodeValue) : NULL;
g_free (nodeValue);

Isn't stringval invalid after the free?  My understanding of
g_strstrip is that it doesn't duplicate the string. Consider:

(nodeValue contains "   doggie   ")
stringval would point to the d...
   doggie   
   ^
 
But freeing nodeValue, frees 
   doggie
^

So stringval now points to free'd memory.  No?
   
Comment 19 bill.haneman 2003-11-17 17:16:11 UTC
no, g_strstrip doesn't alter the input string AFAIK.
Comment 20 bill.haneman 2003-11-17 17:19:05 UTC
glib docs are spectacularly uninformative about this.  I am checking
the glib source code.
Comment 21 bill.haneman 2003-11-17 17:25:18 UTC
David, you are right.  The patch is wrong.  I think DV may also be
wrong, since g_strstrip returns the same memory that it's passed.  

DV, is there some reason why memmove and overwriting buyes with '/0'
will cause problems here?  We are g_free-ing the strings we get from
xmlGetNodeContents, which seems perfectly appropriate here.

I am reverting the patch for the time being while we get clarification.
Comment 22 bill.haneman 2003-11-17 17:33:08 UTC
I kept the g_strstrip calls but removed the g_free.  This appears to
be in line with the implementation of g_strstrip() since it works
in-place and returns the same memory location that it's passed, thus
the return value from g_strstrip can safely be g_freed directly at a
later time.
Comment 23 Daniel Veillard 2003-11-17 17:46:34 UTC
Usually xmlFree() is free(), and g_free() is probably compatible
with free() too but those are assumption ...
libxml2 allows to overwrite the memory API with a different set of
function. If g_strstrip() really reuse the string memory area
(a bit yucky but understandable) then that should work.
sometimes 100% is not 100% :-\

Daniel
Comment 24 David Bolter 2003-11-19 00:19:10 UTC
Bill, does g_strstrup always return the same address it is given? I am
thinking of the case of leading whitespace... (I suppose I could hunt
down the source code too - but if you know already ;-)

If so, is this closeable now?  The visible behaviour seems correct.

Comment 25 bill.haneman 2003-11-19 14:02:21 UTC
g_strstrip (not 'strup') always returns the address it's given, at
least in the current glib implementation.  If that implementation
changes such that a different address is returned, then lots of stuff
will start leaking and breaking, so I think we're safe WRT
bincompat/behavior here.

closing.