Skip to content

Commit ec60156

Browse files
jacobly0andrewrk
authored andcommitted
InternPool: fix leak when the last namespace bucket is full
1 parent 271452d commit ec60156

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/InternPool.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

0 commit comments

Comments
 (0)