From 3bb7833e388cf0354c164ae3a0e07550d0896907 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 1 Dec 2024 12:22:49 -0700 Subject: [PATCH] core: darwin: fix use-after-free Signed-off-by: Stephen Gutekanst --- src/core/Darwin.zig | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/Darwin.zig b/src/core/Darwin.zig index eee8e40a..031b8964 100644 --- a/src/core/Darwin.zig +++ b/src/core/Darwin.zig @@ -130,11 +130,14 @@ fn initWindow( var view = objc.mach.View.allocInit(); view.setLayer(@ptrCast(layer)); - var context: Context = .{ .core = core, .window_id = window_id }; + const context = try core.allocator.create(Context); + context.* = .{ .core = core, .window_id = window_id }; + // TODO(core): free this allocation + { var keyDown = objc.foundation.stackBlockLiteral( ViewCallbacks.keyDown, - &context, + context, null, null, ); @@ -142,7 +145,7 @@ fn initWindow( var keyUp = objc.foundation.stackBlockLiteral( ViewCallbacks.keyUp, - &context, + context, null, null, ); @@ -159,7 +162,7 @@ fn initWindow( var windowWillResize_toSize = objc.foundation.stackBlockLiteral( WindowDelegateCallbacks.windowWillResize_toSize, - &context, + context, null, null, ); @@ -167,7 +170,7 @@ fn initWindow( var windowShouldClose = objc.foundation.stackBlockLiteral( WindowDelegateCallbacks.windowShouldClose, - &context, + context, null, null, );