bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: delwin() and deleting windows with subwindows


From: Bill Gray
Subject: Re: delwin() and deleting windows with subwindows
Date: Thu, 11 Aug 2022 12:35:49 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0

On 8/10/22 20:08, Thomas Dickey wrote:
it depends: in the SVr4 code, child-windows have a link to their parent,
using that to maintain a reference count -- and tell it if there are no
remaining children, and return an error if any remain.  But that's not
enough to just delete all of the children and the parent window, which
would make it nice(r) for applications.

Well, yes... nicer, and apparently we _should_ recursively delete to follow the XSI Curses standard ("It [delwin] must delete subwindows before deleting their parent.")

The only downside I see to recursive deletion would be if you did the following :

   WINDOW *win = newwin( ...);
   WINDOW *sub = subwin( win, ...);

   delwin( win);
   access something in sub;

At present, the delwin() call would fail in ncurses and SVr4. In PDCurses and Solaris X/Open curses, win would be deleted and sub wouldn't. In either case, attempts to access something in sub will still work.

Delete subwindows recursively, and that access attempts to read freed memory. One shouldn't be doing such things; once a parent window is deleted, you shouldn't try to do anything with the subwindow. But I'll bet you that some code does so, and recursive deletion would break that code.

I've therefore reluctantly decided against recursive subwindow deletion for PDCursesMod, and have gone back to having delwin() just return ERR if you try to delete a parent window or a window that wasn't created by the library (just pushed that change to GitHub). It's not as nice, and doesn't follow the XSI Curses standard. But it won't break existing code. And at least it's an improvement over PDCursesMod's previous behavior of simply freeing parent windows without checking for subwindows first...

-- Bill



reply via email to

[Prev in Thread] Current Thread [Next in Thread]