Re: xwininfo dumps core

Tim van der Molen <[email protected]> Fri, 7 Jan 2011 01:14:52 +0100
Newsgroups gmane.os.openbsd.x11
Message-ID <[email protected]>
On Thu, 06 Jan 2011 23:38:33 +0100, frantisek holop wrote:
> hmm, on Thu, Jan 06, 2011 at 10:38:26PM +0100, Matthieu Herrb said that
> > On Thu, Jan 06, 2011 at 10:16:19PM +0100, frantisek holop wrote:
> > > hi there,
> > > 
> > > can anybody reproduce this?  jan 2 snapshot.
> > > 
> > > 
> > > $ xwininfo  
> > > 
> > > xwininfo: Please select the window about which you
> > >           would like information by clicking the
> > >           mouse in that window.
> > > 
> > > xwininfo in free(): error: bogus pointer (double free?) 0xcfbec0c4
> > > xwininfo: Window id: 0xa00006 (can't convert UTF8_STRING to 646)Abort trap (core dumped) 
> > > 
> > 
> > What architecture ? 
> 
> i386
> 
> > What is the (UTF-8) title of the window in question ?
> 
> i dont use utf8 for window titles.  this core dump
> happens with any open window (urxvt, xxxterm, gkrellm2, opera, etc)
> 
> window manager is blackbox from ports

It looks like there are two different problems here.

The UTF-8 string cannot be converted because xwininfo needs iconv for
that ("#ifdef HAVE_ICONV") and our xwininfo is not linked against
libiconv. If you run xwininfo with $LC_ALL set to "de_DE.UTF-8",
xwininfo does print the title (but it still crashes).

The crash itself seems to be fixed by the following diff.

Regards,
Tim

Index: xwininfo.c
===================================================================
RCS file: /cvs/xenocara/app/xwininfo/xwininfo.c,v
retrieving revision 1.4
diff -p -u xwininfo.c
--- xwininfo.c	25 Nov 2010 21:55:09 -0000	1.4
+++ xwininfo.c	6 Jan 2011 23:56:57 -0000
@@ -786,9 +786,9 @@ Display_Window_Id (struct wininfo *w, Bool newline_wan
 {
 #ifdef USE_XCB_ICCCM
     xcb_get_text_property_reply_t wmn_reply;
+    uint8_t got_reply = False;
 #endif
     xcb_get_property_reply_t *prop;
-    uint8_t got_reply = False;
     const char *wm_name = NULL;
     unsigned int wm_name_len = 0;
     xcb_atom_t wm_name_encoding = XCB_NONE;
@@ -807,10 +807,7 @@ Display_Window_Id (struct wininfo *w, Bool newline_wan
 	    wm_name = xcb_get_property_value (prop);
 	    wm_name_len = xcb_get_property_value_length (prop);
 	    wm_name_encoding = prop->type;
-	    got_reply = True;
-	}
-
-	if (!got_reply) { /* No _NET_WM_NAME, check WM_NAME */
+	} else { /* No _NET_WM_NAME, check WM_NAME */
 #ifdef USE_XCB_ICCCM
 	    got_reply = xcb_get_wm_name_reply (dpy, w->wm_name_cookie,
 					       &wmn_reply, NULL);
@@ -825,11 +822,10 @@ Display_Window_Id (struct wininfo *w, Bool newline_wan
 		wm_name = xcb_get_property_value (prop);
 		wm_name_len = xcb_get_property_value_length (prop);
 		wm_name_encoding = prop->type;
-		got_reply = True;
 	    }
 #endif
 	}
-	if (!got_reply || wm_name_len == 0) {
+	if (wm_name_len == 0) {
 	    printf (" (has no name)");
         } else {
 	    if (wm_name_encoding == XCB_ATOM_STRING) {