Attachment "wmForget.diff" to
ticket [9ab6e37e]
added by
emiliano
2026-01-16 13:58:08.
Index: doc/wm.n
==================================================================
--- doc/wm.n
+++ doc/wm.n
@@ -366,10 +366,11 @@
The \fIwindow\fR will be unmapped from the screen and will no longer
be managed by \fBwm\fR. Windows created with the \fBtoplevel\fR
command will be treated like \fBframe\fR windows once they are no
longer managed by \fBwm\fR, however, the \fB\-menu\fR configuration will be
remembered and the menus will return once the widget is managed again.
+If \fIwindow\fR is ".", an error is raised.
.\" METHOD: frame
.TP
\fBwm frame \fIwindow\fR
.
If \fIwindow\fR has been reparented by the window manager into a
Index: macosx/tkMacOSXWm.c
==================================================================
--- macosx/tkMacOSXWm.c
+++ macosx/tkMacOSXWm.c
@@ -2559,17 +2559,24 @@
*----------------------------------------------------------------------
*/
static int
WmForgetCmd(
- TCL_UNUSED(Tk_Window), /* Main window of the application. */
+ Tk_Window mainWin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel or Frame to work with */
- TCL_UNUSED(Tcl_Interp *), /* Current interpreter. */
+ Tcl_Interp *interp, /* Current interpreter. */
TCL_UNUSED(Tcl_Size), /* Number of arguments. */
TCL_UNUSED(Tcl_Obj *const *)) /* Argument objects. */
{
Tk_Window frameWin = (Tk_Window)winPtr;
+
+ if (frameWin == mainWin) {
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "window \".\" can not be forgotten", TCL_INDEX_NONE));
+ Tcl_SetErrorCode(interp, "TK", "WM", "FORGET", ".", NULL);
+ return TCL_ERROR;
+ }
if (Tk_IsTopLevel(frameWin)) {
MacDrawable *macWin;
Tk_MakeWindowExist(frameWin);
Index: tests/wm.test
==================================================================
--- tests/wm.test
+++ tests/wm.test
@@ -2606,10 +2606,17 @@
lappend res [winfo manager .f]
} -cleanup {
destroy .l .f.b .f
unset res
} -result {pack {} wm {}}
+
+test wm-forget-3 {bug [9ab6e37e1ac] - [wm forget] segfault} -setup {
+ destroy .l .f.b .f
+ set res {}
+} -body {
+ wm forget .
+} -returnCodes error -result {window "." can not be forgotten}
#
# TESTFILE CLEANUP
#
Index: unix/tkUnixWm.c
==================================================================
--- unix/tkUnixWm.c
+++ unix/tkUnixWm.c
@@ -1811,17 +1811,24 @@
*----------------------------------------------------------------------
*/
static int
WmForgetCmd(
- TCL_UNUSED(Tk_Window), /* Main window of the application. */
+ Tk_Window mainWin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel or Frame to work with */
- TCL_UNUSED(Tcl_Interp *), /* Current interpreter. */
+ Tcl_Interp *interp, /* Current interpreter. */
TCL_UNUSED(Tcl_Size), /* Number of arguments. */
TCL_UNUSED(Tcl_Obj *const *)) /* Argument objects. */
{
Tk_Window frameWin = (Tk_Window) winPtr;
+
+ if (frameWin == mainWin) {
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "window \".\" can not be forgotten", TCL_INDEX_NONE));
+ Tcl_SetErrorCode(interp, "TK", "WM", "FORGET", ".", NULL);
+ return TCL_ERROR;
+ }
if (Tk_IsTopLevel(frameWin)) {
TkFocusJoin(winPtr);
Tk_UnmapWindow(frameWin);
TkWmDeadWindow(winPtr);
Index: win/tkWinWm.c
==================================================================
--- win/tkWinWm.c
+++ win/tkWinWm.c
@@ -3609,17 +3609,24 @@
*----------------------------------------------------------------------
*/
static int
WmForgetCmd(
- TCL_UNUSED(Tk_Window), /* Main window of the application. */
+ Tk_Window mainWin, /* Main window of the application. */
TkWindow *winPtr, /* Toplevel or Frame to work with */
- TCL_UNUSED(Tcl_Interp *), /* Current interpreter. */
+ Tcl_Interp *interp, /* Current interpreter. */
TCL_UNUSED(Tcl_Size), /* Number of arguments. */
TCL_UNUSED(Tcl_Obj *const *)) /* Argument objects. */
{
Tk_Window frameWin = (Tk_Window) winPtr;
+
+ if (frameWin == mainWin) {
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "window \".\" can not be forgotten", TCL_INDEX_NONE));
+ Tcl_SetErrorCode(interp, "TK", "WM", "FORGET", ".", NULL);
+ return TCL_ERROR;
+ }
if (Tk_IsTopLevel(frameWin)) {
Tk_UnmapWindow(frameWin);
winPtr->flags &= ~(TK_TOP_HIERARCHY|TK_TOP_LEVEL|TK_HAS_WRAPPER|TK_WIN_MANAGED);
Tk_MakeWindowExist((Tk_Window)winPtr->parentPtr);