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) {...@@ -2046,7 +2046,7 @@ pub const Key = union(enum) {
2046 },2046 },
2047 /// This type originates from a reification via `@Type`, or from an anonymous initialization.2047 /// This type originates from a reification via `@Type`, or from an anonymous initialization.
2048 /// It is hashed based on its ZIR instruction index and fields, attributes, etc.2048 /// 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.
2050 reified: struct {2050 reified: struct {
2051 /// A `reify`, `struct_init`, `struct_init_ref`, or `struct_init_anon` instruction.2051 /// A `reify`, `struct_init`, `struct_init_ref`, or `struct_init_anon` instruction.
2052 zir_index: TrackedInst.Index,2052 zir_index: TrackedInst.Index,
...@@ -11287,7 +11287,8 @@ pub fn createNamespace(...@@ -11287,7 +11287,8 @@ pub fn createNamespace(
11287 return reused_namespace_index;11287 return reused_namespace_index;
11288 }11288 }
11289 const namespaces = local.getMutableNamespaces(gpa);11289 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) {
11291 try namespaces.ensureUnusedCapacity(1);11292 try namespaces.ensureUnusedCapacity(1);
11292 var arena = namespaces.arena.promote(namespaces.gpa);11293 var arena = namespaces.arena.promote(namespaces.gpa);
11293 defer namespaces.arena.* = arena.state;11294 defer namespaces.arena.* = arena.state;
...@@ -11298,10 +11299,9 @@ pub fn createNamespace(...@@ -11298,10 +11299,9 @@ pub fn createNamespace(
11298 const unwrapped_namespace_index: NamespaceIndex.Unwrapped = .{11299 const unwrapped_namespace_index: NamespaceIndex.Unwrapped = .{
11299 .tid = tid,11300 .tid = tid,
11300 .bucket_index = namespaces.mutate.len - 1,11301 .bucket_index = namespaces.mutate.len - 1,
11301 .index = local.mutate.namespaces.last_bucket_len,11302 .index = last_bucket_len,
11302 };11303 };
11303 local.mutate.namespaces.last_bucket_len =11304 local.mutate.namespaces.last_bucket_len = last_bucket_len + 1;
11304 (unwrapped_namespace_index.index + 1) & Local.namespaces_bucket_mask;
11305 const namespace_index = unwrapped_namespace_index.wrap(ip);11305 const namespace_index = unwrapped_namespace_index.wrap(ip);
11306 ip.namespacePtr(namespace_index).* = initialization;11306 ip.namespacePtr(namespace_index).* = initialization;
11307 return namespace_index;11307 return namespace_index;