#307 Fix crash on calling place in a half-dead application

51. [place] (1)
Anton Kovalenko

The following code segfaults on last tk CVS head (8.5 seems ok):

package require Tk
bind . <Destroy> {puts [place slaves .]}
destroy .

Problem: Tk_PlaceObjCmd uses Tk_MainWindow(interp) to get a window needed for TkGetWindowFromObj. Main window of an interp is removed from main window list _before_ <Destroy> bindings are evaluated. Tk_MainWindow(interp) starts to return NULL, [place] doesn't check for it, and a bad thing happens.

Solution: other geometry managers, [grid]/[pack] at least, install an interp main window pointer as a command's client data (see tkWindow.c). During the time this report is about, main window is half-dead and removed from main window list, but not deallocated, and [grid]/[pack] have no problem accessing it. Changing tkPlace.c along these lines is trivial, as the [place] clientData is unused by now.

P.S. among other commands not taking main window as their ClientData, [wm] looks suspicious (it's formally a geometry manager, at least). I'll look deeper into it when I have more time.


  • trivial fix for [place] command crash (see above)

    • status: open --> closed-fixed