Commit 44ab80b
committed
gh-156946: Unlink a curses panel before dropping its user pointer
PyCursesPanel_Dealloc() dropped the panel's user pointer first, through
PyCursesPanel_Clear(), and only then called del_panel() and remove_lop().
Dropping that reference can run a __del__, and until del_panel() has run
the dying panel is still on the panel stack and still in lop, so
top_panel(), bottom_panel(), above() and below() hand the finalizer a new
reference to an object whose refcount is already zero. Releasing that
reference re-enters the deallocator and the interpreter segfaults.
Take the panel out of lop and off the panel stack first, and release the
user pointer and the window afterwards. set_panel_userptr() and
panel_userptr() need the PANEL, so they still run before del_panel().
remove_lop() now also runs before del_panel(), which closes a second
window where the registry held an entry whose PANEL had been freed.
The deallocator cannot simply call PyCursesPanel_Clear() in the new order
because that function is also tp_clear, where del_panel() must not run.1 parent 1a2e3a0 commit 44ab80b
3 files changed
Lines changed: 28 additions & 8 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Library
- Modules
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2428 | 2428 | | |
2429 | 2429 | | |
2430 | 2430 | | |
| 2431 | + | |
| 2432 | + | |
| 2433 | + | |
| 2434 | + | |
| 2435 | + | |
| 2436 | + | |
| 2437 | + | |
| 2438 | + | |
| 2439 | + | |
| 2440 | + | |
| 2441 | + | |
| 2442 | + | |
| 2443 | + | |
| 2444 | + | |
| 2445 | + | |
| 2446 | + | |
2431 | 2447 | | |
2432 | 2448 | | |
2433 | 2449 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
457 | | - | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
458 | 464 | | |
459 | 465 | | |
460 | 466 | | |
461 | 467 | | |
462 | 468 | | |
463 | 469 | | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
| 470 | + | |
| 471 | + | |
471 | 472 | | |
472 | 473 | | |
473 | 474 | | |
| |||
0 commit comments