Fix use-after-free by moving config-reload into the manage cycle

This commit is contained in:
Ben Buhse 2026-01-31 14:08:46 -06:00
commit 4157dd67f6
No known key found for this signature in database
GPG key ID: 7916ACFCD38FD0B4
3 changed files with 33 additions and 14 deletions

View file

@ -21,6 +21,13 @@ xkb_bindings: *XkbBindings,
// WM Configuration
config: *Config,
/// State consumed in manage() phase, reset at end of manage().
pending_manage: PendingManage = .{},
pub const PendingManage = struct {
config: ?*Config = null,
};
pub fn create(
wl_display: *wl.Display,
wl_registry: *wl.Registry,
@ -52,6 +59,22 @@ pub fn destroy(context: *Context) void {
utils.allocator.destroy(context);
}
pub fn manage(context: *Context) void {
defer context.pending_manage = .{};
if (context.pending_manage.config) |new_config| {
// Destroy all existing bindings
var it = context.xkb_bindings.bindings.safeIterator(.forward);
while (it.next()) |binding| {
binding.link.remove();
binding.destroy();
}
context.config.destroy();
context.config = new_config;
context.initialized = false;
}
}
const std = @import("std");
const wayland = @import("wayland");