From d0803dbd217c57e5d649e87e6fbecfa25ac39df0 Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Thu, 9 Oct 2025 02:24:41 +0000 Subject: [PATCH] Fix memory leak and absolute path bugs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/bun.js/api/ExtractJob.zig | 1 + src/bun.js/api/TarballJob.zig | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bun.js/api/ExtractJob.zig b/src/bun.js/api/ExtractJob.zig index 6d5e830e36..27f645d8fb 100644 --- a/src/bun.js/api/ExtractJob.zig +++ b/src/bun.js/api/ExtractJob.zig @@ -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); } } diff --git a/src/bun.js/api/TarballJob.zig b/src/bun.js/api/TarballJob.zig index 59ed50b10d..e81ba2a4bf 100644 --- a/src/bun.js/api/TarballJob.zig +++ b/src/bun.js/api/TarballJob.zig @@ -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 {