Skip to content

vxfw App.init: dangling pointer from stack-local buffer #311

@elogir

Description

@elogir

/// Create an application. We require stable pointers to do the set up, so this will create an App
/// object on the heap. Call destroy when the app is complete to reset terminal state and release
/// resources
pub fn init(allocator: Allocator) !App {
var app: App = .{
.allocator = allocator,
.tty = undefined,
.vx = try vaxis.init(allocator, .{
.system_clipboard_allocator = allocator,
.kitty_keyboard_flags = .{
.report_events = true,
},
}),
.timers = std.ArrayList(vxfw.Tick){},
.wants_focus = null,
.buffer = undefined,
};
app.tty = try vaxis.Tty.init(&app.buffer);
return app;
}

Looks like init constructs app on the stack and passes &app.buffer to Tty.init. app is then returned, which copies the struct to the caller's location. Any pointer that Tty stored to app.buffer now dangles, as it still references the old stack frame.

Even though the comment above says

We require stable pointers to do the set up, so this will create an App object on the heap

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions