mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-24 09:05:48 -04:00
terminal: don’t unref a not-yet-referenced key-binding set
Key-binding sets are bound to a seat/configuration pair. The conf reference is done when a new terminal instance is created. When that same terminal instance is destroyed, the key binding set is unref:ed. If the terminal instance is destroyed *before* the key binding set has been referenced, we’ll still unref it. This creates an imbalance. In particular, when the there is exactly one other terminal instance referencing that same key binding set, that terminal instance will trigger a foot server crash as soon as it receives a key press/release event. This happens because the next-to-last terminal instance brought the reference count of the binding set down to 0, causing it to be free:d. Thus, we *must* reference the binding set *before* we can error out (when instantiating a new terminal instance). At this point, we don’t yet have a valid terminal instance. But, that’s ok, because all the key_binding_new_for_term() did with the terminal instance was get the "struct wayland" and "struct config" pointers. So, rename the function and simply pass these pointers explicitly. Similarly, change key_binding_for() to take a "struct config" pointer, rather than a "struct terminal" pointer. Also rename key_binding_unref_term() -> key_binding_unref().
This commit is contained in:
parent
c311229b9e
commit
d2e67689ea
6 changed files with 35 additions and 31 deletions
11
terminal.c
11
terminal.c
|
|
@ -1089,6 +1089,11 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
|||
goto close_fds;
|
||||
}
|
||||
|
||||
/* Need to register *very* early (before the first “goto err”), to
|
||||
* ensure term_destroy() doesn’t unref a key-binding we haven’t
|
||||
* yet ref:d */
|
||||
key_binding_new_for_conf(wayl->key_binding_manager, wayl, conf);
|
||||
|
||||
int ptmx_flags;
|
||||
if ((ptmx_flags = fcntl(ptmx, F_GETFL)) < 0 ||
|
||||
fcntl(ptmx, F_SETFL, ptmx_flags | O_NONBLOCK) < 0)
|
||||
|
|
@ -1266,8 +1271,6 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
|||
|
||||
memcpy(term->colors.table, term->conf->colors.table, sizeof(term->colors.table));
|
||||
|
||||
key_binding_new_for_term(wayl->key_binding_manager, term);
|
||||
|
||||
/* Initialize the Wayland window backend */
|
||||
if ((term->window = wayl_win_init(term, token)) == NULL)
|
||||
goto err;
|
||||
|
|
@ -1583,7 +1586,7 @@ term_destroy(struct terminal *term)
|
|||
if (term == NULL)
|
||||
return 0;
|
||||
|
||||
key_binding_unref_term(term->wl->key_binding_manager, term);
|
||||
key_binding_unref(term->wl->key_binding_manager, term->conf);
|
||||
|
||||
tll_foreach(term->wl->terms, it) {
|
||||
if (it->item == term) {
|
||||
|
|
@ -2885,7 +2888,7 @@ term_mouse_grabbed(const struct terminal *term, const struct seat *seat)
|
|||
get_current_modifiers(seat, &mods, NULL, 0);
|
||||
|
||||
const struct key_binding_set *bindings =
|
||||
key_binding_for(term->wl->key_binding_manager, term, seat);
|
||||
key_binding_for(term->wl->key_binding_manager, term->conf, seat);
|
||||
const xkb_mod_mask_t override_modmask = bindings->selection_overrides;
|
||||
bool override_mods_pressed = (mods & override_modmask) == override_modmask;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue