diff options
| author | Helmut Eller | 2025-11-11 08:25:30 +0100 |
|---|---|---|
| committer | Helmut Eller | 2026-03-13 15:11:36 +0100 |
| commit | 817873579017a2c0f5c4cb7f94bf5ae1f22ba42b (patch) | |
| tree | 178dc1d90720385eba96dbee0373d05069300554 | |
| parent | 64dd95bc380c0dcc4ab918a31e2796336c13b4ed (diff) | |
| download | emacs-scratch/gc-handles.tar.gz emacs-scratch/gc-handles.zip | |
Avoid crashes when displaying menu help-echo stringsscratch/gc-handles
Use GC handles for help-echo strings instead of raw pointers.
* src/w32menu.c (add_menu_item): Store GC handles.
(w32_menu_display_help): Dereference the string.
(w32_free_submenu_strings): Free GC handles.
| -rw-r--r-- | src/w32menu.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/w32menu.c b/src/w32menu.c index 77d33a3554d..08a74a31cc3 100644 --- a/src/w32menu.c +++ b/src/w32menu.c | |||
| @@ -1622,21 +1622,16 @@ add_menu_item (HMENU menu, widget_value *wv, HMENU item) | |||
| 1622 | /* Set help string for menu item. Leave it as a pointer to | 1622 | /* Set help string for menu item. Leave it as a pointer to |
| 1623 | a Lisp_String until it is ready to be displayed, since GC | 1623 | a Lisp_String until it is ready to be displayed, since GC |
| 1624 | can happen while menus are active. */ | 1624 | can happen while menus are active. */ |
| 1625 | /* FIXME/igc: store a gc_handle in info.dwItemData */ | ||
| 1626 | Lisp_Object help = gc_handle_value (wv->help); | 1625 | Lisp_Object help = gc_handle_value (wv->help); |
| 1627 | if (!NILP (help)) | 1626 | if (!NILP (help)) |
| 1628 | { | 1627 | { |
| 1629 | /* We use XUNTAG below because in a 32-bit build | ||
| 1630 | --with-wide-int we cannot pass a Lisp_Object | ||
| 1631 | via a DWORD member of MENUITEMINFO. */ | ||
| 1632 | /* As of Jul-2012, w32api headers say that dwItemData | 1628 | /* As of Jul-2012, w32api headers say that dwItemData |
| 1633 | has DWORD type, but that's a bug: it should actually | 1629 | has DWORD type, but that's a bug: it should actually |
| 1634 | be ULONG_PTR, which is correct for 32-bit and 64-bit | 1630 | be ULONG_PTR, which is correct for 32-bit and 64-bit |
| 1635 | Windows alike. MSVC headers get it right; hopefully, | 1631 | Windows alike. MSVC headers get it right; hopefully, |
| 1636 | MinGW headers will, too. */ | 1632 | MinGW headers will, too. */ |
| 1637 | eassert (STRINGP (help)); | 1633 | eassert (STRINGP (help)); |
| 1638 | info.dwItemData = (ULONG_PTR) XUNTAG (help, Lisp_String, | 1634 | info.dwItemData = (ULONG_PTR) gc_handle_for (help); |
| 1639 | struct Lisp_String); | ||
| 1640 | } | 1635 | } |
| 1641 | if (wv->button_type == BUTTON_TYPE_RADIO) | 1636 | if (wv->button_type == BUTTON_TYPE_RADIO) |
| 1642 | { | 1637 | { |
| @@ -1729,7 +1724,7 @@ w32_menu_display_help (HWND owner, HMENU menu, UINT item, UINT flags) | |||
| 1729 | 1724 | ||
| 1730 | help = | 1725 | help = |
| 1731 | info.dwItemData | 1726 | info.dwItemData |
| 1732 | ? make_lisp_ptr ((void *) info.dwItemData, Lisp_String) | 1727 | ? gc_handle_value ((gc_handle) info.dwItemData) |
| 1733 | : Qnil; | 1728 | : Qnil; |
| 1734 | } | 1729 | } |
| 1735 | 1730 | ||
| @@ -1771,6 +1766,9 @@ w32_free_submenu_strings (HMENU menu) | |||
| 1771 | #endif | 1766 | #endif |
| 1772 | local_free (info.dwItemData); | 1767 | local_free (info.dwItemData); |
| 1773 | } | 1768 | } |
| 1769 | /* Free the help-echo handle. */ | ||
| 1770 | else if (info.dwItemData) | ||
| 1771 | free_gc_handle ((gc_handle) info.dwItemData); | ||
| 1774 | 1772 | ||
| 1775 | /* Recurse down submenus. */ | 1773 | /* Recurse down submenus. */ |
| 1776 | if (info.hSubMenu) | 1774 | if (info.hSubMenu) |