diff options
author | 2023-01-19 10:53:01 +0200 | |
---|---|---|
committer | 2023-01-19 00:53:01 -0800 | |
commit | 8bdcded5c10aa9e280c33c829988ad8363feba9f (patch) | |
tree | e54a759f04b9662f0500a7642e151d6016806725 | |
parent | c0ec61cf16633492befd8f560ff6970db01c2a1d (diff) | |
download | bun-8bdcded5c10aa9e280c33c829988ad8363feba9f.tar.gz bun-8bdcded5c10aa9e280c33c829988ad8363feba9f.tar.zst bun-8bdcded5c10aa9e280c33c829988ad8363feba9f.zip |
fix memory reference issues (#1841)
-rw-r--r-- | src/install/install.zig | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/install/install.zig b/src/install/install.zig index 86e0ca532..3ce46b3ce 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -1375,7 +1375,7 @@ pub const PackageManager = struct { resolve_tasks: TaskChannel, timestamp_for_manifest_cache_control: u32 = 0, extracted_count: u32 = 0, - alias_map: std.ArrayHashMapUnmanaged(PackageID, String, ArrayIdentityContext, false) = .{}, + alias_map: std.ArrayHashMapUnmanaged(PackageID, string, ArrayIdentityContext, false) = .{}, default_features: Features = Features{}, summary: Lockfile.Package.Diff.Summary = Lockfile.Package.Diff.Summary{}, env: *DotEnv.Loader, @@ -2069,7 +2069,11 @@ pub const PackageManager = struct { Features.npm, )); - try this.alias_map.put(this.allocator, package.meta.id, alias); + const buf = this.lockfile.buffers.string_bytes.items; + if (!alias.eql(name, buf, buf)) { + const alias_str = try this.allocator.dupe(u8, alias.slice(buf)); + try this.alias_map.put(this.allocator, package.meta.id, alias_str); + } if (!behavior.isEnabled(if (this.isRootDependency(dependency_id)) this.options.local_package_features @@ -5530,7 +5534,7 @@ pub const PackageManager = struct { resolution: Resolution, ) void { const buf = this.lockfile.buffers.string_bytes.items; - const alias = if (this.manager.alias_map.get(package_id)) |str| str.slice(buf) else name; + const alias = this.manager.alias_map.get(package_id) orelse name; std.mem.copy(u8, &this.destination_dir_subpath_buf, alias); this.destination_dir_subpath_buf[alias.len] = 0; var destination_dir_subpath: [:0]u8 = this.destination_dir_subpath_buf[0..alias.len :0]; |