fix: fully deinit keybind.Mode to avoid race when switching modes

This commit is contained in:
CJ van den Berg 2025-11-05 16:39:35 +01:00
parent 983e518f69
commit 8b50c7a3af
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
2 changed files with 21 additions and 8 deletions

View file

@ -100,7 +100,7 @@ const Handler = struct {
pub const Mode = struct {
allocator: std.mem.Allocator,
input_handler: EventHandler,
input_handler: ?EventHandler,
event_handler: ?EventHandler = null,
mode: []const u8,
@ -121,11 +121,24 @@ pub const Mode = struct {
}
pub fn deinit(self: *Mode) void {
if (self.deinit_command) |deinit_command|
deinit_command.execute_const();
self.allocator.free(self.mode);
self.input_handler.deinit();
if (self.deinit_command) |deinit_command| deinit_command.execute_const();
if (self.event_handler) |eh| eh.deinit();
if (self.input_handler) |ih| ih.deinit();
self.allocator.free(self.mode);
self.deinit_command = null;
self.event_handler = null;
self.input_handler = null;
self.mode = &.{};
self.name = "";
self.line_numbers = .inherit;
self.keybind_hints = &.{};
self.cursor_shape = null;
self.selection_style = .normal;
self.init_command = null;
self.deinit_command = null;
self.initialized = false;
}
};