From ec60156f187a9baa02e0ac7e15ee7a864f098dcf Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Sun, 29 Dec 2024 04:50:32 -0500 Subject: InternPool: fix leak when the last namespace bucket is full --- src/InternPool.zig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/InternPool.zig') diff --git a/src/InternPool.zig b/src/InternPool.zig index 681d2b4957..fdeddcfa2f 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -2046,7 +2046,7 @@ pub const Key = union(enum) { }, /// This type originates from a reification via `@Type`, or from an anonymous initialization. /// It is hashed based on its ZIR instruction index and fields, attributes, etc. - /// To avoid making this key overly complex, the type-specific data is hased by Sema. + /// To avoid making this key overly complex, the type-specific data is hashed by Sema. reified: struct { /// A `reify`, `struct_init`, `struct_init_ref`, or `struct_init_anon` instruction. zir_index: TrackedInst.Index, @@ -11287,7 +11287,8 @@ pub fn createNamespace( return reused_namespace_index; } const namespaces = local.getMutableNamespaces(gpa); - if (local.mutate.namespaces.last_bucket_len == 0) { + const last_bucket_len = local.mutate.namespaces.last_bucket_len & Local.namespaces_bucket_mask; + if (last_bucket_len == 0) { try namespaces.ensureUnusedCapacity(1); var arena = namespaces.arena.promote(namespaces.gpa); defer namespaces.arena.* = arena.state; @@ -11298,10 +11299,9 @@ pub fn createNamespace( const unwrapped_namespace_index: NamespaceIndex.Unwrapped = .{ .tid = tid, .bucket_index = namespaces.mutate.len - 1, - .index = local.mutate.namespaces.last_bucket_len, + .index = last_bucket_len, }; - local.mutate.namespaces.last_bucket_len = - (unwrapped_namespace_index.index + 1) & Local.namespaces_bucket_mask; + local.mutate.namespaces.last_bucket_len = last_bucket_len + 1; const namespace_index = unwrapped_namespace_index.wrap(ip); ip.namespacePtr(namespace_index).* = initialization; return namespace_index; -- cgit v1.2.3