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:
Claude Bot
2025-10-09 02:24:41 +00:00
parent 58e7919674
commit d0803dbd21
2 changed files with 5 additions and 1 deletions

View File

@@ -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);
}
}

View File

@@ -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 {