Skip to content

Commit

Permalink
InternPool: fix leak when the last namespace bucket is full
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobly0 committed Dec 29, 2024
1 parent 01081cc commit 576991a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/InternPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 576991a

Please sign in to comment.