mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
font: SharedGridSet.Key needs to clone the DerivedConfig
Key contains pointers into DerivedConfig. Each surface has its own DerivedConfig. This would cause memory corruption if the surface that opened the initial font grid deallocates. Instead, let's make sure Key owns its own DerivedConfig.
This commit is contained in:
@ -367,7 +367,9 @@ pub const DerivedConfig = struct {
|
||||
@"adjust-strikethrough-position": ?Metrics.Modifier,
|
||||
@"adjust-strikethrough-thickness": ?Metrics.Modifier,
|
||||
|
||||
pub fn init(alloc_gpa: Allocator, config: *const Config) !DerivedConfig {
|
||||
/// Initialize a DerivedConfig. The config should be either a
|
||||
/// config.Config or another DerivedConfig to clone from.
|
||||
pub fn init(alloc_gpa: Allocator, config: anytype) !DerivedConfig {
|
||||
var arena = ArenaAllocator.init(alloc_gpa);
|
||||
errdefer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
@ -447,13 +449,20 @@ pub const Key = struct {
|
||||
|
||||
pub fn init(
|
||||
alloc_gpa: Allocator,
|
||||
config: *const DerivedConfig,
|
||||
config_src: *const DerivedConfig,
|
||||
font_size: DesiredSize,
|
||||
) !Key {
|
||||
var arena = ArenaAllocator.init(alloc_gpa);
|
||||
errdefer arena.deinit();
|
||||
const alloc = arena.allocator();
|
||||
|
||||
// Clone our configuration. We need to do this because the lifetime
|
||||
// of the derived config is usually shorter than that of a key
|
||||
// and we use pointers into the derived config for the key. We
|
||||
// can remove this if we wanted by dupe-ing the memory we use
|
||||
// from DerivedConfig below.
|
||||
var config = try DerivedConfig.init(alloc, config_src);
|
||||
|
||||
var descriptors = std.ArrayList(discovery.Descriptor).init(alloc);
|
||||
defer descriptors.deinit();
|
||||
for (config.@"font-family".list.items) |family| {
|
||||
|
Reference in New Issue
Block a user