diff options
| author | Isaac Freund <ifreund@ifreund.xyz> | 2020-08-21 20:06:26 +0200 |
|---|---|---|
| committer | Isaac Freund <ifreund@ifreund.xyz> | 2020-08-21 21:06:59 +0200 |
| commit | 4a334829f39c840aa11d60299fc5098bfa949bd6 (patch) | |
| tree | bf56f73cd479d53521fc843e1e9bb5c59d2517da | |
| parent | c7c1934b70f074bd15ca59b795aa998d8397469a (diff) | |
| download | river-4a334829f39c840aa11d60299fc5098bfa949bd6.tar.gz river-4a334829f39c840aa11d60299fc5098bfa949bd6.tar.xz | |
config: handle alloc failure in Mapping init
| -rw-r--r-- | river/Mapping.zig | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/river/Mapping.zig b/river/Mapping.zig index 61df624..3d80624 100644 --- a/river/Mapping.zig +++ b/river/Mapping.zig @@ -31,8 +31,12 @@ pub fn init( modifiers: u32, command_args: []const []const u8, ) !Self { - var owned_args = try allocator.alloc([]u8, command_args.len); - for (command_args) |arg, i| owned_args[i] = try std.mem.dupe(allocator, u8, arg); + const owned_args = try allocator.alloc([]u8, command_args.len); + errdefer allocator.free(owned_args); + for (command_args) |arg, i| { + errdefer for (owned_args[0..i]) |a| allocator.free(a); + owned_args[i] = try std.mem.dupe(allocator, u8, arg); + } return Self{ .keysym = keysym, .modifiers = modifiers, |
