command: dupe mode name memory
The hashmap doesn't take ownership of the memory pointer to by these slices, so we need to dupe them to avoid use-after-free.
This commit is contained in:
parent
08d630567f
commit
dfb03fd0cb
@ -61,12 +61,15 @@ pub fn init(self: *Self) !void {
|
|||||||
self.outer_padding = 8;
|
self.outer_padding = 8;
|
||||||
|
|
||||||
self.mode_to_id = std.StringHashMap(usize).init(util.gpa);
|
self.mode_to_id = std.StringHashMap(usize).init(util.gpa);
|
||||||
|
errdefer self.mode_to_id.deinit();
|
||||||
try self.mode_to_id.putNoClobber("normal", 0);
|
try self.mode_to_id.putNoClobber("normal", 0);
|
||||||
|
|
||||||
self.modes = std.ArrayList(std.ArrayList(Mapping)).init(util.gpa);
|
self.modes = std.ArrayList(std.ArrayList(Mapping)).init(util.gpa);
|
||||||
|
errdefer self.modes.deinit();
|
||||||
try self.modes.append(std.ArrayList(Mapping).init(util.gpa));
|
try self.modes.append(std.ArrayList(Mapping).init(util.gpa));
|
||||||
|
|
||||||
self.float_filter = std.ArrayList([*:0]const u8).init(util.gpa);
|
self.float_filter = std.ArrayList([*:0]const u8).init(util.gpa);
|
||||||
|
errdefer self.float_filter.deinit();
|
||||||
|
|
||||||
// Float views with app_id "float"
|
// Float views with app_id "float"
|
||||||
try self.float_filter.append("float");
|
try self.float_filter.append("float");
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const c = @import("../c.zig");
|
const c = @import("../c.zig");
|
||||||
|
const util = @import("../util.zig");
|
||||||
|
|
||||||
const Error = @import("../command.zig").Error;
|
const Error = @import("../command.zig").Error;
|
||||||
const Mapping = @import("../Mapping.zig");
|
const Mapping = @import("../Mapping.zig");
|
||||||
@ -45,7 +46,9 @@ pub fn declareMode(
|
|||||||
return Error.CommandFailed;
|
return Error.CommandFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
try config.mode_to_id.putNoClobber(new_mode_name, config.modes.items.len);
|
const owned_name = try std.mem.dupe(util.gpa, u8, new_mode_name);
|
||||||
errdefer _ = config.mode_to_id.remove(new_mode_name);
|
errdefer util.gpa.free(owned_name);
|
||||||
|
try config.mode_to_id.putNoClobber(owned_name, config.modes.items.len);
|
||||||
|
errdefer _ = config.mode_to_id.remove(owned_name);
|
||||||
try config.modes.append(std.ArrayList(Mapping).init(allocator));
|
try config.modes.append(std.ArrayList(Mapping).init(allocator));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user