mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 20:09:04 +00:00
Replace catch bun.outOfMemory() with safer alternatives (#22141)
Replace `catch bun.outOfMemory()`, which can accidentally catch non-OOM-related errors, with either `bun.handleOom` or a manual `catch |err| switch (err)`. (For internal tracking: fixes STAB-1070) --------- Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
This commit is contained in:
@@ -248,7 +248,7 @@ pub const StandaloneModuleGraph = struct {
|
||||
};
|
||||
|
||||
const source_files = serialized.sourceFileNames();
|
||||
const slices = bun.default_allocator.alloc(?[]u8, source_files.len * 2) catch bun.outOfMemory();
|
||||
const slices = bun.handleOom(bun.default_allocator.alloc(?[]u8, source_files.len * 2));
|
||||
|
||||
const file_names: [][]const u8 = @ptrCast(slices[0..source_files.len]);
|
||||
const decompressed_contents_slice = slices[source_files.len..][0..source_files.len];
|
||||
@@ -598,7 +598,7 @@ pub const StandaloneModuleGraph = struct {
|
||||
std.fs.path.sep_str,
|
||||
zname,
|
||||
&.{0},
|
||||
}) catch bun.outOfMemory();
|
||||
}) catch |e| bun.handleOom(e);
|
||||
zname = zname_z[0..zname_z.len -| 1 :0];
|
||||
continue;
|
||||
}
|
||||
@@ -683,7 +683,7 @@ pub const StandaloneModuleGraph = struct {
|
||||
var file = bun.sys.File{ .handle = cloned_executable_fd };
|
||||
const writer = file.writer();
|
||||
const BufferedWriter = std.io.BufferedWriter(512 * 1024, @TypeOf(writer));
|
||||
var buffered_writer = bun.default_allocator.create(BufferedWriter) catch bun.outOfMemory();
|
||||
var buffered_writer = bun.handleOom(bun.default_allocator.create(BufferedWriter));
|
||||
buffered_writer.* = .{
|
||||
.unbuffered_writer = writer,
|
||||
};
|
||||
@@ -929,7 +929,7 @@ pub const StandaloneModuleGraph = struct {
|
||||
var free_self_exe = false;
|
||||
const self_exe = if (self_exe_path) |path| brk: {
|
||||
free_self_exe = true;
|
||||
break :brk allocator.dupeZ(u8, path) catch bun.outOfMemory();
|
||||
break :brk bun.handleOom(allocator.dupeZ(u8, path));
|
||||
} else if (target.isDefault())
|
||||
bun.selfExePath() catch |err| {
|
||||
return CompileResult.fail(std.fmt.allocPrint(allocator, "failed to get self executable path: {s}", .{@errorName(err)}) catch "failed to get self executable path");
|
||||
@@ -958,7 +958,7 @@ pub const StandaloneModuleGraph = struct {
|
||||
}
|
||||
|
||||
free_self_exe = true;
|
||||
break :blk allocator.dupeZ(u8, dest_z) catch bun.outOfMemory();
|
||||
break :blk bun.handleOom(allocator.dupeZ(u8, dest_z));
|
||||
};
|
||||
|
||||
defer if (free_self_exe) {
|
||||
@@ -1358,7 +1358,7 @@ pub const StandaloneModuleGraph = struct {
|
||||
const compressed_file = compressed_codes[@intCast(index)].slice(this.map.bytes);
|
||||
const size = bun.zstd.getDecompressedSize(compressed_file);
|
||||
|
||||
const bytes = bun.default_allocator.alloc(u8, size) catch bun.outOfMemory();
|
||||
const bytes = bun.handleOom(bun.default_allocator.alloc(u8, size));
|
||||
const result = bun.zstd.decompress(bytes, compressed_file);
|
||||
|
||||
if (result == .err) {
|
||||
|
||||
Reference in New Issue
Block a user