Skip to content

Commit 143b881

Browse files
committed
Stop leaking memory.
1 parent e56c400 commit 143b881

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/librustc_query_system/query/caches.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,13 @@ impl<'tcx, K: Eq + Hash, V: 'tcx> CacheSelector<K, V> for ArenaCacheSelector<'tc
143143
}
144144

145145
pub struct ArenaCache<'tcx, K, V> {
146-
arena: WorkerLocal<&'tcx TypedArena<(V, DepNodeIndex)>>,
147-
phantom: PhantomData<K>,
146+
arena: WorkerLocal<TypedArena<(V, DepNodeIndex)>>,
147+
phantom: PhantomData<(K, &'tcx V)>,
148148
}
149149

150150
impl<'tcx, K, V> Default for ArenaCache<'tcx, K, V> {
151151
fn default() -> Self {
152-
ArenaCache {
153-
arena: WorkerLocal::new(|_| &*Box::leak(Box::new(TypedArena::default()))),
154-
phantom: PhantomData,
155-
}
152+
ArenaCache { arena: WorkerLocal::new(|_| TypedArena::default()), phantom: PhantomData }
156153
}
157154
}
158155

@@ -162,7 +159,8 @@ impl<'tcx, K: Eq + Hash, V: 'tcx> QueryStorage for ArenaCache<'tcx, K, V> {
162159

163160
fn store_nocache(&self, value: Self::Value) -> Self::Stored {
164161
let value = self.arena.alloc((value, DepNodeIndex::INVALID));
165-
&value.0
162+
let value = unsafe { &*(&value.0 as *const _) };
163+
&value
166164
}
167165
}
168166

@@ -204,6 +202,7 @@ impl<'tcx, K: Eq + Hash, V: 'tcx> QueryCache for ArenaCache<'tcx, K, V> {
204202
index: DepNodeIndex,
205203
) -> Self::Stored {
206204
let value = self.arena.alloc((value, index));
205+
let value = unsafe { &*(value as *const _) };
207206
lock_sharded_storage.insert(key, value);
208207
&value.0
209208
}

0 commit comments

Comments
 (0)