mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Fix memory leak and absolute path bugs
Critical fixes from CodeRabbit review: 1. Memory leak: Free duplicated key if map insertion fails - extractToMemory: Added errdefer to reclaim key on error 2. Absolute path bug: Support absolute destination in tarball - Was always using cwd.openFile, failed on absolute paths - Now detects absolute and uses openFileAbsolute 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -238,6 +238,7 @@ pub const ExtractJob = struct {
|
||||
}
|
||||
|
||||
const key = try allocator.dupe(u8, normalized);
|
||||
errdefer allocator.free(key);
|
||||
try this.files.put(key, buf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,10 @@ pub const TarballJob = struct {
|
||||
}
|
||||
|
||||
if (this.destination) |destination| {
|
||||
const file = std.fs.cwd().openFile(destination, .{}) catch return error.CannotOpenFile;
|
||||
const file = (if (std.fs.path.isAbsolute(destination))
|
||||
std.fs.openFileAbsolute(destination, .{})
|
||||
else
|
||||
std.fs.cwd().openFile(destination, .{})) catch return error.CannotOpenFile;
|
||||
defer file.close();
|
||||
this.bytes_written = (file.stat() catch return error.CannotStatFile).size;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user