renderer/opengl: fix memory leak when copying font features

This commit is contained in:
Mitchell Hashimoto
2024-11-20 14:07:28 -08:00
parent 03b60ab2ef
commit f8a8b0464c
3 changed files with 15 additions and 8 deletions

View File

@ -3478,10 +3478,17 @@ pub const RepeatableString = struct {
/// Deep copy of the struct. Required by Config.
pub fn clone(self: *const Self, alloc: Allocator) Allocator.Error!Self {
// Copy the list and all the strings in the list.
const list = try self.list.clone(alloc);
for (list.items) |*item| {
const copy = try alloc.dupeZ(u8, item.*);
item.* = copy;
var list = try std.ArrayListUnmanaged([:0]const u8).initCapacity(
alloc,
self.list.items.len,
);
errdefer {
for (list.items) |item| alloc.free(item);
list.deinit(alloc);
}
for (self.list.items) |item| {
const copy = try alloc.dupeZ(u8, item);
list.appendAssumeCapacity(copy);
}
return .{ .list = list };

View File

@ -379,7 +379,7 @@ pub const DerivedConfig = struct {
const custom_shaders = try config.@"custom-shader".clone(alloc);
// Copy our font features
const font_features = try config.@"font-feature".list.clone(alloc);
const font_features = try config.@"font-feature".clone(alloc);
// Get our font styles
var font_styles = font.CodepointResolver.StyleStatus.initFill(true);
@ -398,7 +398,7 @@ pub const DerivedConfig = struct {
return .{
.background_opacity = @max(0, @min(1, config.@"background-opacity")),
.font_thicken = config.@"font-thicken",
.font_features = font_features,
.font_features = font_features.list,
.font_styles = font_styles,
.cursor_color = if (!cursor_invert and config.@"cursor-color" != null)

View File

@ -290,7 +290,7 @@ pub const DerivedConfig = struct {
const custom_shaders = try config.@"custom-shader".clone(alloc);
// Copy our font features
const font_features = try config.@"font-feature".list.clone(alloc);
const font_features = try config.@"font-feature".clone(alloc);
// Get our font styles
var font_styles = font.CodepointResolver.StyleStatus.initFill(true);
@ -309,7 +309,7 @@ pub const DerivedConfig = struct {
return .{
.background_opacity = @max(0, @min(1, config.@"background-opacity")),
.font_thicken = config.@"font-thicken",
.font_features = font_features,
.font_features = font_features.list,
.font_styles = font_styles,
.cursor_color = if (!cursor_invert and config.@"cursor-color" != null)