Core: fix potential printTitle leak

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-04-28 12:23:08 -07:00 committed by Stephen Gutekanst
parent 136c86e929
commit d690814b16

View file

@ -66,6 +66,11 @@ pub fn printTitle(
comptime fmt: []const u8, comptime fmt: []const u8,
args: anytype, args: anytype,
) !void { ) !void {
// Free any previous window title slice
// TODO: reuse allocations
if (core.get(window_id, .title)) |slice| core.state().allocator.free(slice);
// Allocate and assign a new window title slice.
const slice = try std.fmt.allocPrintZ(core.state().allocator, fmt, args); const slice = try std.fmt.allocPrintZ(core.state().allocator, fmt, args);
try core.set(window_id, .title, slice); try core.set(window_id, .title, slice);
} }