Skip to content

closing View windows after multiple View(x) crashes

6 messages · Bill Dunlap, Brian Ripley, Ben Bolker

#
R version 2.8.0 Under development (unstable) (2008-07-07 r46046)
i686-pc-linux-gnu

locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base


x = cbind(a=1:10,b=1:10)

View(x)
View(x)
View(x)
View(x)

   then try to close the latest window by clicking on the "x" 
(close-window) icon in the corner.
   I can usually provoke a segmentation fault this way ...
   Ubuntu Hardy, up to date.

   [on a related topic, can anyone tell me why View() usually
doesn't work when I try it on someone else's Mac?  I don't
use Macs myself so haven't tried to figure this one out -- I
know, I could write to R-SIG-MAC about it ...]

   Ben Bolker

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20080729/883ecda7/attachment.bin>
#
On Tue, 29 Jul 2008, Ben Bolker wrote:

            
Does it work any better for you if you edit src/modules/X11/dataentry.c
and add a call to Rsync(DE) after the XDestroyWindow(iodisplay, DE->iowindow)
in closewin()?

I don't get your crash, but I have to click twice on the X button
to get the View window to close and valgrind complains about the use
of freed memory, DE->prot in the event loop in R_ProcessX11Events()
            if(ioevent.xclient.message_type == _XA_WM_PROTOCOLS
               && ioevent.xclient.data.l[0] == DE->prot) {
                /* user clicked on `close' aka `destroy' */
                done = 1;
            }
The trouble seems to be that this code sets done=1, causing the calls
        closewin(DE);
        free(DE);
but without the Rsync call in closewin(), the window doesn't close
immediately and later sends some messages to its event handler, causing
the use of the freed DE.  (I sometimes use the idiom free(DE);DE=NULL;
instead of just free(DE) to make sure no one tries to use DE afterwards,
but valgrind does that job better.)

When I make closewin() call Rsync(DE) then I only have to click
once on the X button to close the View window, the event loop
doesn't get reentered, and valgrind seems happy.

I'm using R on "Red Hat Enterprise Linux WS release 4 (Nahant Update 3)"
with the Cygwin X server on a Windows XP laptop.

----------------------------------------------------------------------------
Bill Dunlap
Insightful Corporation
bill at insightful dot com

 "All statements in this message represent the opinions of the author and do
 not necessarily reflect Insightful Corporation policy or position."
#
That works like a charm.  Thanks!

   Ben Bolker
Bill Dunlap wrote:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20080729/1d633b3d/attachment.bin>
#
On Tue, 29 Jul 2008, Ben Bolker wrote:

            
Good.  Here is the patch I used.  (I didn't send it
earlier because my code still had a bunch of Rprintf
calls in it to track the event loop activity.

Index: src/modules/X11/dataentry.c
===================================================================
--- src/modules/X11/dataentry.c	(revision 46139)
+++ src/modules/X11/dataentry.c	(working copy)
@@ -1881,6 +1881,7 @@
 #endif
     XDestroyWindow(iodisplay, DE->iowindow);
     /* XCloseDisplay(iodisplay); */
+    Rsync(DE);
 }

 #define USE_Xt 1

Valgrind reports a slew of memory leaks when R closes
after using View(), but it didn't show any use of freed
or uninitialized memory after that change.

----------------------------------------------------------------------------
Bill Dunlap
Insightful Corporation
bill at insightful dot com

 "All statements in this message represent the opinions of the author and do
 not necessarily reflect Insightful Corporation policy or position."
#
We have found elsewhere that the need to use XSync is very dependent on 
the window manager. What manager were you using?

I'll add the call in any case.
On Tue, 29 Jul 2008, Bill Dunlap wrote:

            

  
    
#
I'm using Gnome.

   Ben
Prof Brian Ripley wrote: