Skip Menu |

This queue is for tickets about the Tk CPAN distribution.

Report information
The Basics
Id: 16053
Status: resolved
Worked: 1 hour (60 min)
Priority: 0/
Queue: Tk

People
Owner: Nobody in particular
Requestors: zentara [...] zentara.net
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 804.027
Fixed in: (no value)



Subject: gtk2 > 2.8.0 apps are causing segfaults in Tk , with readv(3, [{"_GTK_LOAD_ICONTHEMES", 20},
Start any Perl/Tk app. If you have gtk+-2.8.7 installed, run gtk-demo. Click on Button Boxes to run it's demo, the Perl/Tk app will segfault. If you restart the Perl/Tk app, subsequent clicking of Button Box will NOT segfault Tk. Only the first time does it. I ran strace on the Perl/Tk apps, and when it segfaults, the line readv(3, [{"_GTK_LOAD_ICONTHEMES", 20}, {"", 0}], 2) = 20 always appears in strace before the crash. When I revert to earlier Gtk2 versions, say 2.8.0, it does not occur. I first noticed this when getting mail with sylpheed-claws would crash my running Tk apps. It does NOT crash Tcl/Tk apps, so it must be in the Perl/Tk conversion. I have seen this on ICEWM and KDE under OpenSuSE 10, and on my customized Slackware system, running the very latest libraries...glibc2.3.6, gcc-4.02, latest gtk+ libs. I have reported this to the gtk2 people, but they claim that it is a Perl/Tk bug since it is the Tk program which crashes.
Subject: Re: [cpan #16053] gtk2 > 2.8.0 apps are causing segfaults in Tk ,with readv(3, [{"_GTK_LOAD_ICONTHEMES", 20},
To: bug-Tk [...] rt.cpan.org
Date: Wed, 30 Nov 2005 19:28:20 +0000
From: Nick Ing-Simmons <nick [...] ing-simmons.net>
RT-Send-Cc:
Guest via RT <bug-Tk@rt.cpan.org> writes: Show quoted text
>This message about Tk was sent to you by guest <> via rt.cpan.org > >Full context and any attached attachments can be found at: <URL: >https://rt.cpan.org/Ticket/Display.html?id=16053 > > >Start any Perl/Tk app. If you have gtk+-2.8.7 installed, run gtk-demo. Click >on Button Boxes to run it's demo, the Perl/Tk app will segfault. If you >restart the Perl/Tk app, subsequent clicking of Button Box will NOT segfault >Tk. Only the first time does it. I ran strace on the Perl/Tk apps, and when it >segfaults, the line readv(3, [{"_GTK_LOAD_ICONTHEMES", 20}, {"", 0}], 2) = 20 >always appears in strace before the crash. When I revert to earlier Gtk2 >versions, say 2.8.0, it does not occur. I first noticed this when getting mail >with sylpheed-claws would crash my running Tk apps. It does NOT crash Tcl/Tk >apps, so it must be in the Perl/Tk conversion. I have seen this on ICEWM and >KDE under OpenSuSE 10, and on my customized Slackware system, running the very >latest libraries...glibc2.3.6, gcc-4.02, latest gtk+ libs. I have reported >this to the gtk2 people, but they claim that it is a Perl/Tk bug since it is >the Tk program which crashes.
As one toolkit is crashing another my guess is that GTK has put something in a X Property that per/Tk does not like. As it is a SEGV I am guessing that something that has been marked as a 32-bit property (or perhaps perk/Tk has _assumed_ is 32 bit) has a number of bytes which isn't a multiple of 4. Is file handle 3 that is being readv()ed the X socket (further back strace). Or as it SEGVs if by chance you can get a backtrace from gdb
Thanks for more-of the strace. As both read/write are happening to fd=4 (number changed in last post) it is likely the X socket, but if you still have the _full_ trace to hand if you can look for a call like: socket(PF_FILE, SOCK_STREAM, 0) = 4 to confirm that it might help. How do I tell which version of gtk2 I have? This seems to suggest I have 2.4.9 ? nick@llama:/home/p4work/Tkutf8> grep -i version /opt/gnome/lib/pkgconfig/gtk+-2.0.pc gtk_binary_version=2.4.0 Version: 2.4.9 nick@llama:/home/p4work/Tkutf8> (I have SuSE9.2 + pile of online-updates, but SuSE don't use bleading edge.) Given that I seem to be way behind and not really a Gnome hacker I am reluctant to install anything as I don't know what goes where or depends on what. So gdb back trace would still be a help, But that really needs a perl (and hence a Tk) built with -g (I usually use -O2 -g) to be really helpful, but even function name trace you should get without -g may be a hint.
Hmm, If I have read Xproto.h correctly read(4, "\241 b\16\1\0\300\0\306\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 32) = 32 That is a ClientMessage Event \2xx is Event \41 = Decimal 33 = ClientMessage ' ' is just a padding byte b\16 is sequence number \1\0\300\0 is Window \0\306\1\0 is Atom which identifies Message So will take a look at what Tk does when it gets unexpected ClientMessage-s.
1st attempt to fix: In tkGlue.c near line 4580 (in function LangClientMessage) is: if (!SvROK(w)) { Tk_Window mainwin = (Tk_Window)((((TkWindow*)tkwin)->mainPtr)->winPtr); w = TkToWidget(mainwin,NULL); } Please try changing that to if (!SvROK(w) && tkwin) { Tk_Window mainwin = (Tk_Window)((((TkWindow*)tkwin)->mainPtr)->winPtr); w = TkToWidget(mainwin,NULL); } I suspect gtk is sending the "_GTK_LOAD_ICON_THEME" message to one of perl/Tk's X windows which don't correspond to Tk widgets. So core Tk has failed to find a "tkwin" and perl glue code's attempt to locate MainWindow is doomed.
From: Ben Crowell
Show quoted text
> if (!SvROK(w) && tkwin)
I've applied this patch, and it doesn't fix the problem. According to gdb, the crash is inside Tk_HandleEvent().
From: Ben Crowell
The following patch to tkEvent.c cures the crashes: if (eventPtr && winPtr && winPtr->mainPtr) { LangClientMessage(winPtr->mainPtr->interp, (Tk_Window) winPtr, eventPtr); } However, I don't know if the patch is sufficient, because I don't understand all the surrounding code. It could be that omitting the call to LangClientMessage causes a loss of integrity to Perl/Tk's data, for instance.
Latest patch has been confirmed as a fix.
From: m_lin.nooning [...] comcast.net
On Thu Dec 29 07:48:14 2005, NI-S wrote: Show quoted text
> > Latest patch has been confirmed as a fix.
I added the patch. However, I still get a Segmentation Fault within 20 button clicks of the short script I am pasting below, on at least two Linux variants. Doing a Google search for "Segmentation fault after destroying non-dependent window" will reveal that this is a problem on a number of Linux platforms. It works fine on Windows. #!/usr/bin/perl -w # File test_pop_up_a_message.pl use Tk; use strict; our $answer = "okay"; ############ sub response { my ($we_top, $button_response) = @_; $we_top->destroy; $answer = $button_response; } ############ sub pop_up_a_message { my ($message) = @_; my $okay_button; my $exit_button; print("Can allways see\n"); my $we_top = new MainWindow; print("Cannot see if Segmentation fault\n"); $we_top->Label ( -text => $message)->pack(); #......... $okay_button = $we_top->Button( -text => 'Okay', -command => [ \&response, $we_top, 'okay' ] )->pack(); #......... $exit_button = $we_top->Button( -text => 'Exit', -command => [ \&response, $we_top, 'exit' ] )->pack(); #......... $we_top->MainLoop; } ############ my $message = ""; my $count = 1; while ($answer eq "okay") { $message = " On at least Slackware and Mandriva, Perl 5.8.7 or 5.8.8, this code will\n" . " get a Segmentation fault within 20 clicks of Okay \n " . $count++ . "\n"; pop_up_a_message($message); print ("You pressed $answer\n"); }
From: zentara [...] zentara.net
On Fri Feb 24 06:41:12 2006, guest wrote: Show quoted text
> On Thu Dec 29 07:48:14 2005, NI-S wrote:
> > > > Latest patch has been confirmed as a fix.
> > I added the patch. However, I still get a Segmentation Fault within 20 > button clicks of the short script I am pasting below, on at least two > Linux variants. Doing a Google search for "Segmentation fault after > destroying non-dependent window" will reveal that this is a problem on a > number of Linux platforms. It works fine on Windows.
Hi, I think you posted this bug under the wrong category. This bug thread was caused by Gtk2 apps interfering with Tk. Your problem dosn't even mention Gtk2. By the way, I ran your script without any segfaults, many times. I'm using linux on a customized slackware.
From: zentara [...] zentara.net
On Fri Feb 24 06:41:12 2006, guest wrote: Show quoted text
> On Thu Dec 29 07:48:14 2005, NI-S wrote:
> > > > Latest patch has been confirmed as a fix.
> > I added the patch. However, I still get a Segmentation Fault within 20 > button clicks of the short script I am pasting below, on at least two > Linux variants. Doing a Google search for "Segmentation fault after > destroying non-dependent window" will reveal that this is a problem on a > number of Linux platforms. It works fine on Windows. > >
Oops, sorry for the premature dismissal...... I did finally see your bug. And there is a mention of readv(3, [{"2400001 gTK_LOAD_ICONTHEMES\ in the strace output lines preceding the segfault. So I guess that this bug has not been fully worked out. I'll try to start up my debugging version of Tk, and see where it is crashing.
From: zentara [...] zentara.net
On Fri Feb 24 06:41:12 2006, guest wrote: Show quoted text
> On Thu Dec 29 07:48:14 2005, NI-S wrote:
> > > > Latest patch has been confirmed as a fix.
> > I added the patch. However, I still get a Segmentation Fault within 20 > button clicks of the short script I am pasting below, on at least two > Linux variants. Doing a Google search for "Segmentation fault after > destroying non-dependent window" will reveal that this is a problem on a > number of Linux platforms. It works fine on Windows.
This is the output of a debugging Tk, with the tkEvent.c patch applied, when I run you script. When running with a debugging Tk, with plain Perl 5.8.7 with original patch of tkEvent.c:986 if(interp){...} At segfault: ##################################################### Program received signal SIGSEGV, Segmentation fault. 0xb7d1861f in Tk_GetOptionValue () from /usr/lib/perl5/site_perl/5.8.7/i686-linux-thread-multi-ld/auto/Tk/Tk.so (gdb) bt #0 0xb7d1861f in Tk_GetOptionValue () from /usr/lib/perl5/site_perl/5.8.7/i686-linux-thread-multi-ld/auto/Tk/Tk.so #1 0xb7cc723a in FrameWidgetObjCmd () from /usr/lib/perl5/site_perl/5.8.7/i686-linux-thread-multi-ld/auto/Tk/Tk.so #2 0xb7c95d06 in Call_Tk (info=0x83d87b8, items=3, args=0x825a184) at tkGlue.c:2283 #3 0xb7c9729c in XStoWidget (my_perl=0x8154f68, cv=0x8290534) at tkGlue.c:2662 #4 0x080c6aa1 in Perl_pp_entersub () #5 0x080bf309 in Perl_runops_standard () #6 0x08064a7b in perl_run () #7 0x0805fe5d in main () (gdb) q ######################################################## Maybe Nick Ing Simmons will know what changes need to be made.
From: m.nooning [...] comcast.net
There is another clue from where I submitted this bug to the (now closed) bugzilla report at http://bugzilla.gnome.org/show_bug.cgi?id=332989 I had included the already shown short script and stack trace. There, a Matthias Clasen replied: ----paste Tk bug. It must not segfault on receiving a ClientMessage ----end paste Does Matthias' statement add a helpful clue to anyone?
From: zentara [...] zentara.net
On Wed Mar 01 11:11:35 2006, guest wrote: Show quoted text
> There is another clue from where I submitted this bug to the (now > closed) bugzilla report at > http://bugzilla.gnome.org/show_bug.cgi?id=332989 > I had included the already shown short script and stack trace. > > There, a Matthias Clasen replied: > ----paste > Tk bug. It must not segfault on receiving a ClientMessage > ----end paste > > Does Matthias' statement add a helpful clue to anyone?
Well Matthias' response was directed to the original bug, which is the bug originally discussed in this thread. I posted this problem to the Gtk buglist, and they responded, that no matter if Gtk was involved in causing the segfault, it was a Tk problem....because Tk should not be responding to Gtk's window manager signals. That problem was apparently fixed to my (and others) satisfaction by the patch. Since patching, I've not seen any segfaults, and I run alot of Tk and Gtk2 code. Your program does indeed raise the spector that this bug is not totally fixed....i.e. there probably is another place in the code which needs patching. I cannot easily see where, from the results of my backtrace. It will take the mind of Nick Ing Simmons, with his more intimate knowledge. Furthermore, your particular code segfaults on it's own, not as a result of something in a gtk2 app. In the original bug, a button press in a Gtk2 app, would kill ALL running Tk programs. Your code snippet only kills itself, so it is a different type of problem. Additionally, your example snippet itself may be causing it, by the way it is written. All I can say, is that I have not seen any problem with this bug since the patch, with the exception of your code. I also posted it on comp.lang.perl.tk, and no one else is complaining about noticing it. Sooo........in summary, I think it is a different bug, (although there is a similarity in the gtk_load_iconthemes appearing in the strace output before the crash. The main differences between your new bug and the original is.... 1. Your code kills itself and only itself, where in the original bug, a button click in a gtk2 app would kill ALL running Tk apps. 2. Nobody is reporting seeing the bug, except when running your test code.
From: zentara [...] zentara.net
On Wed Mar 01 11:11:35 2006, guest wrote: Show quoted text
> There is another clue from where I submitted this bug to the (now > closed) bugzilla report at > http://bugzilla.gnome.org/show_bug.cgi?id=332989 > I had included the already shown short script and stack trace. > > There, a Matthias Clasen replied: > ----paste > Tk bug. It must not segfault on receiving a ClientMessage > ----end paste > > Does Matthias' statement add a helpful clue to anyone?
Hi, just an addendum, to explain why I think it may actually be the way you wrote your code snippet, which is causing the segfaults. The way you create a new mainwindow and event loop in a subroutine, and repeatedly call that sub, is bound to lead to segfaults. You do not want to constantly be creating a new mainwindow and redefining the event loop from a sub. If you do it that way, ( which you would never do in practice) you need to clean up after the old mainwindow and loop. In almost all programs, you want to create the mainwindow and event loop just once, and subsequent windows should be new toplevels, or dialogs. Without careful cleanup, the code can keep track of which mainwindow is the current, and which event loop is current. You are attempting a sort of infinite recursion with your code.
There is a pertinent reason why the test code given is relevent. Besides just surfacing the bug. I have an application wherein the user makes a choice from a Perl/Tk pop up menu. Once a choice is made, the pop up is destroyed and something then runs in the background. When the user chosen task is done running, one of a number of different pop ups could happen, depending upon the results. One could be a pop up wherein the user is asked if he wants to run it again. Different home grown Perl modules have different pop ups. Most are very simple informational messages but they need to be popped up, and then destroyed when the user clicks an Okay button. Hence I really do need to be able to create a pop up in a routine, destroy it, create another one from another routine, destroy it, and so on. That is why the test code really does reflect the problem space. It runs just fine on Windows, by the way. No problems whatsoever on Windows. It is only the Linux varients that have the problem. I cannot imagine that Tk really has a problem with the concept of having a popup attempted multiple times. This has to be a bug that can be resolved. I do a careful cleanup each time the user clicks the Okay button by explicitly using the "destroy" method, such as $we_top->destroy. Isn't that supposed to destory MainWindow and take care of any needed cleanup? Shouldn't I then be free to call a routine that might (or might not) pop up a new message? Is there something I am missing?
From: zentara [...] zentara.net
On Wed Mar 01 16:34:01 2006, guest wrote: Show quoted text
> There is a pertinent reason why the test code given is relevent. > Besides just surfacing the bug. > > I have an application wherein the user makes a choice from a Perl/Tk pop > up menu. Once a choice is made, the pop up is destroyed and something > then runs in the background. When the user chosen task is done running,
I don't want to carry on a design discussion in this Tk bug forum. All I can say is that there are many better ways to design what you are trying to do. The code is not more complicated, but it will run better. The approach you are taking seems logical to someone used to doing linear procedural programming, but gui programming involves a thing called the "event loop", and your method of design sort of ignores it's crucial role in running the gui. That is probably why you would get unpredictable results in the segfaults, sometimes a few clicks, sometimes 20. It starts depending on system load, and timing between clicks processing your rebuilding a new mainwindow. Finally , just running $mw->destroy does not clean up, because you are still attempting to use the old event-loop to launch the next event-loop, if the timing gets bad, it segfaults. Anyways, you can post this problem on comp.lang.perl.tk or at http://perlmonks.org and show your code, and explain exactly what you want to do. I will give my ideas, and others may have better solutions. But be assured, there are ways to do what you want, without causing a segfault, where only 1 mainwindow is created, and the rest is done thru toplevels or dialogs.
Subject: Re: [rt.cpan.org #16053] gtk2 > 2.8.0 apps are causing segfaultsin Tk , with readv(3, [{"_GTK_LOAD_ICONTHEMES", 20},
Date: Sat, 11 Mar 2006 17:47:09 +0000
To: bug-Tk [...] rt.cpan.org
From: Nick Ing-Simmons <nick [...] ing-simmons.net>
Guest via RT <bug-Tk@rt.cpan.org> writes: Show quoted text
><URL: http://rt.cpan.org/Ticket/Display.html?id=16053 > > >Oops, sorry for the premature dismissal...... I did finally see your >bug. And there is a mention of readv(3, [{"2400001 gTK_LOAD_ICONTHEMES\ > in the strace output lines preceding the segfault. So I guess that >this bug has not been fully worked out. I'll try to start up my >debugging version of Tk, and see where it is crashing.
I am not following all this yet, but the bug fix cannot stop Gtk sending the message - so message will still be read from the X socket, which is what the strace fragment shows. The bug fix causes Tk to ignore the message. The message likely gets sent by the window manager when a new top level window is created.
Subject: Re: [rt.cpan.org #16053] gtk2 > 2.8.0 apps are causing segfaultsin Tk , with readv(3, [{"_GTK_LOAD_ICONTHEMES", 20},
Date: Sun, 12 Mar 2006 06:02:24 -0500
To: bug-Tk [...] rt.cpan.org
From: zentara <zentara [...] zentara.net>
On Sat, 11 Mar 2006 12:47:33 -0500 (EST) "Nick Ing-Simmons via RT" <bug-Tk@rt.cpan.org> wrote: Show quoted text
> ><URL: http://rt.cpan.org/Ticket/Display.html?id=16053 > > >Guest via RT <bug-Tk@rt.cpan.org> writes:
>><URL: http://rt.cpan.org/Ticket/Display.html?id=16053 > >> >>Oops, sorry for the premature dismissal...... I did finally see your >>bug. And there is a mention of readv(3, [{"2400001 gTK_LOAD_ICONTHEMES\ >> in the strace output lines preceding the segfault. So I guess that >>this bug has not been fully worked out. I'll try to start up my >>debugging version of Tk, and see where it is crashing.
> >I am not following all this yet, but the bug fix cannot stop >Gtk sending the message - so message will still be read from the X socket, >which is what the strace fragment shows. > >The bug fix causes Tk to ignore the message. > >The message likely gets sent by the window manager when a new top level >window is created. >
Don't worry about this one......it was caused by a bad program design, calling MainLoop multiple times from a sub. He has been shown the right way to write it. -- I'm not really a human, but I play one on earth. http://zentara.net/japh.html
From: peter.willendrup [...] risoe.dk
Hello there, On Sun Mar 12 06:05:22 2006, zentara@zentara.net wrote: Show quoted text
> Don't worry about this one......it was caused by a bad program design, > calling MainLoop multiple times from a sub. He has been shown the
right way Show quoted text
> to write it.
I have similar behaviour of a perl-Tk based app which to the best of my knowledge does not call MainLoop multiple times from a sub. Please find attached output from a strace run. Peter Willendrup

Message body is not shown because it is too large.

From: peter.willendrup [...] risoe.dk
On Mon Mar 27 07:48:37 2006, guest wrote: Show quoted text
> I have similar behaviour of a perl-Tk based app which to the best of my > knowledge does not call MainLoop multiple times from a sub.
Oops. Feel free to close the bug, my mistake - patch fixes my problem. Peter