authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-12-29 04:50:32-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-29 15:28:40-05:00
logec60156f187a9baa02e0ac7e15ee7a864f098dcf
tree16944042364dc40cadcb204c32909b5d7fa8fa85
parent271452d225803770d29af1c9401fc610254d23c2

InternPool: fix leak when the last namespace bucket is full


1 files changed, 5 insertions(+), 5 deletions(-)

src/InternPool.zig+5-5
......@@ -2046,7 +2046,7 @@ pub const Key = union(enum) {
20462046 },
20472047 /// This type originates from a reification via `@Type`, or from an anonymous initialization.
20482048 /// It is hashed based on its ZIR instruction index and fields, attributes, etc.
2049 /// To avoid making this key overly complex, the type-specific data is hased by Sema.
2049 /// To avoid making this key overly complex, the type-specific data is hashed by Sema.
20502050 reified: struct {
20512051 /// A `reify`, `struct_init`, `struct_init_ref`, or `struct_init_anon` instruction.
20522052 zir_index: TrackedInst.Index,
......@@ -11287,7 +11287,8 @@ pub fn createNamespace(
1128711287 return reused_namespace_index;
1128811288 }
1128911289 const namespaces = local.getMutableNamespaces(gpa);
11290 if (local.mutate.namespaces.last_bucket_len == 0) {
11290 const last_bucket_len = local.mutate.namespaces.last_bucket_len & Local.namespaces_bucket_mask;
11291 if (last_bucket_len == 0) {
1129111292 try namespaces.ensureUnusedCapacity(1);
1129211293 var arena = namespaces.arena.promote(namespaces.gpa);
1129311294 defer namespaces.arena.* = arena.state;
......@@ -11298,10 +11299,9 @@ pub fn createNamespace(
1129811299 const unwrapped_namespace_index: NamespaceIndex.Unwrapped = .{
1129911300 .tid = tid,
1130011301 .bucket_index = namespaces.mutate.len - 1,
11301 .index = local.mutate.namespaces.last_bucket_len,
11302 .index = last_bucket_len,
1130211303 };
11303 local.mutate.namespaces.last_bucket_len =
11304 (unwrapped_namespace_index.index + 1) & Local.namespaces_bucket_mask;
11304 local.mutate.namespaces.last_bucket_len = last_bucket_len + 1;
1130511305 const namespace_index = unwrapped_namespace_index.wrap(ip);
1130611306 ip.namespacePtr(namespace_index).* = initialization;
1130711307 return namespace_index;