Change errdefers in create()/init() functions
They should use gpa.destroy() instead of foo.destroy() because (most) of them have fields that may not be initialized by the first error, so the foo.destroy() could crash.
This commit is contained in:
parent
2b336299eb
commit
6bf607b759
11 changed files with 12 additions and 11 deletions
|
|
@ -78,6 +78,7 @@ pub fn initSurface(bar: *Bar) !void {
|
||||||
|
|
||||||
pub fn deinit(bar: *Bar) void {
|
pub fn deinit(bar: *Bar) void {
|
||||||
bar.configured = false;
|
bar.configured = false;
|
||||||
|
bar.timezone.deinit();
|
||||||
if (bar.wl_surface) |wl_surface| {
|
if (bar.wl_surface) |wl_surface| {
|
||||||
wl_surface.destroy();
|
wl_surface.destroy();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ link: wl.list.Link,
|
||||||
|
|
||||||
pub fn create(river_input_device_v1: *river.InputDeviceV1) !*InputDevice {
|
pub fn create(river_input_device_v1: *river.InputDeviceV1) !*InputDevice {
|
||||||
const input_device = try utils.gpa.create(InputDevice);
|
const input_device = try utils.gpa.create(InputDevice);
|
||||||
errdefer input_device.destroy();
|
errdefer utils.gpa.destroy(input_device);
|
||||||
|
|
||||||
input_device.* = .{
|
input_device.* = .{
|
||||||
.river_input_device_v1 = river_input_device_v1,
|
.river_input_device_v1 = river_input_device_v1,
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ libinput_devices: wl.list.Head(LibinputDevice, .link),
|
||||||
pub fn create(context: *Context, river_input_manager_v1: *river.InputManagerV1, river_libinput_config_v1: *river.LibinputConfigV1) !*InputManager {
|
pub fn create(context: *Context, river_input_manager_v1: *river.InputManagerV1, river_libinput_config_v1: *river.LibinputConfigV1) !*InputManager {
|
||||||
log.debug("Creating new InputManager", .{});
|
log.debug("Creating new InputManager", .{});
|
||||||
const im = try utils.gpa.create(InputManager);
|
const im = try utils.gpa.create(InputManager);
|
||||||
errdefer im.destroy();
|
errdefer utils.gpa.destroy(im);
|
||||||
|
|
||||||
im.* = .{
|
im.* = .{
|
||||||
.context = context,
|
.context = context,
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ link: wl.list.Link,
|
||||||
|
|
||||||
pub fn create(context: *Context, river_libinput_device_v1: *river.LibinputDeviceV1) !*LibinputDevice {
|
pub fn create(context: *Context, river_libinput_device_v1: *river.LibinputDeviceV1) !*LibinputDevice {
|
||||||
const libinput_device = try utils.gpa.create(LibinputDevice);
|
const libinput_device = try utils.gpa.create(LibinputDevice);
|
||||||
errdefer libinput_device.destroy();
|
errdefer utils.gpa.destroy(libinput_device);
|
||||||
|
|
||||||
libinput_device.* = .{
|
libinput_device.* = .{
|
||||||
.context = context,
|
.context = context,
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ pub const PendingManage = struct {
|
||||||
|
|
||||||
pub fn create(context: *Context, river_output_v1: *river.OutputV1) !*Output {
|
pub fn create(context: *Context, river_output_v1: *river.OutputV1) !*Output {
|
||||||
var output = try utils.gpa.create(Output);
|
var output = try utils.gpa.create(Output);
|
||||||
errdefer output.destroy();
|
errdefer utils.gpa.destroy(output);
|
||||||
|
|
||||||
const bar = Bar.init(context, output) catch |e| blk: {
|
const bar = Bar.init(context, output) catch |e| blk: {
|
||||||
log.err("Failed to create a bar: {}", .{e});
|
log.err("Failed to create a bar: {}", .{e});
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ pub const PointerOp = union(enum) {
|
||||||
|
|
||||||
pub fn create(context: *Context, river_seat_v1: *river.SeatV1) !*Seat {
|
pub fn create(context: *Context, river_seat_v1: *river.SeatV1) !*Seat {
|
||||||
var seat = try utils.gpa.create(Seat);
|
var seat = try utils.gpa.create(Seat);
|
||||||
errdefer seat.destroy();
|
errdefer utils.gpa.destroy(seat);
|
||||||
|
|
||||||
seat.* = .{
|
seat.* = .{
|
||||||
.context = context,
|
.context = context,
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ pub const PendingRender = struct {
|
||||||
|
|
||||||
pub fn create(context: *Context, river_window_v1: *river.WindowV1, output: ?*Output) !*Window {
|
pub fn create(context: *Context, river_window_v1: *river.WindowV1, output: ?*Output) !*Window {
|
||||||
var window = try utils.gpa.create(Window);
|
var window = try utils.gpa.create(Window);
|
||||||
errdefer window.destroy();
|
errdefer utils.gpa.destroy(window);
|
||||||
|
|
||||||
window.* = .{
|
window.* = .{
|
||||||
.context = context,
|
.context = context,
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ orphan_windows: wl.list.Head(Window, .link),
|
||||||
|
|
||||||
pub fn create(context: *Context, window_manager_v1: *river.WindowManagerV1) !*WindowManager {
|
pub fn create(context: *Context, window_manager_v1: *river.WindowManagerV1) !*WindowManager {
|
||||||
const wm = try utils.gpa.create(WindowManager);
|
const wm = try utils.gpa.create(WindowManager);
|
||||||
errdefer wm.destroy();
|
errdefer utils.gpa.destroy(wm);
|
||||||
|
|
||||||
wm.* = .{
|
wm.* = .{
|
||||||
.context = context,
|
.context = context,
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ const XkbBinding = struct {
|
||||||
|
|
||||||
fn create(xkb_binding_v1: *river.XkbBindingV1, command: Command, context: *Context) !*XkbBinding {
|
fn create(xkb_binding_v1: *river.XkbBindingV1, command: Command, context: *Context) !*XkbBinding {
|
||||||
var xkb_binding = try utils.gpa.create(XkbBinding);
|
var xkb_binding = try utils.gpa.create(XkbBinding);
|
||||||
errdefer xkb_binding.destroy();
|
errdefer utils.gpa.destroy(xkb_binding);
|
||||||
|
|
||||||
xkb_binding.* = .{
|
xkb_binding.* = .{
|
||||||
.xkb_binding_v1 = xkb_binding_v1,
|
.xkb_binding_v1 = xkb_binding_v1,
|
||||||
|
|
@ -405,7 +405,7 @@ bindings: wl.list.Head(XkbBinding, .link),
|
||||||
|
|
||||||
pub fn create(context: *Context, xkb_bindings_v1: *river.XkbBindingsV1) !*XkbBindings {
|
pub fn create(context: *Context, xkb_bindings_v1: *river.XkbBindingsV1) !*XkbBindings {
|
||||||
const xkb_bindings = try utils.gpa.create(XkbBindings);
|
const xkb_bindings = try utils.gpa.create(XkbBindings);
|
||||||
errdefer xkb_bindings.destroy();
|
errdefer utils.gpa.destroy(xkb_bindings);
|
||||||
|
|
||||||
xkb_bindings.* = .{
|
xkb_bindings.* = .{
|
||||||
.context = context,
|
.context = context,
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ pub const Flag = struct {
|
||||||
kind: enum { boolean, arg },
|
kind: enum { boolean, arg },
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn parser(comptime Arg: type, comptime flags: []const Flag) type {
|
pub fn Parser(comptime Arg: type, comptime flags: []const Flag) type {
|
||||||
switch (Arg) {
|
switch (Arg) {
|
||||||
// TODO consider allowing []const u8
|
// TODO consider allowing []const u8
|
||||||
[:0]const u8, [*:0]const u8 => {}, // ok
|
[:0]const u8, [*:0]const u8 => {}, // ok
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,7 @@ fn run(wl_display: *wl.Display, context: *Context) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parseArgs() void {
|
fn parseArgs() void {
|
||||||
const result = flags.parser([*:0]const u8, &.{
|
const result = flags.Parser([*:0]const u8, &.{
|
||||||
.{ .name = "h", .kind = .boolean },
|
.{ .name = "h", .kind = .boolean },
|
||||||
.{ .name = "version", .kind = .boolean },
|
.{ .name = "version", .kind = .boolean },
|
||||||
.{ .name = "log-level", .kind = .arg },
|
.{ .name = "log-level", .kind = .arg },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue