diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2020-04-01 14:29:55 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2020-04-28 11:34:53 +0200 |
| commit | 143b8816a3cc478ec8d214efade98245eb5b3c82 (patch) | |
| tree | cba395dadf793c995a4524fadabfbf74c607f4ab /src | |
| parent | e56c4004326cb83ec433788fa8f2fc6cd4dd391a (diff) | |
| download | rust-143b8816a3cc478ec8d214efade98245eb5b3c82.tar.gz rust-143b8816a3cc478ec8d214efade98245eb5b3c82.zip | |
Stop leaking memory.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_query_system/query/caches.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/librustc_query_system/query/caches.rs b/src/librustc_query_system/query/caches.rs index d921bcdcdd3..e2fe6f7207b 100644 --- a/src/librustc_query_system/query/caches.rs +++ b/src/librustc_query_system/query/caches.rs @@ -143,16 +143,13 @@ impl<'tcx, K: Eq + Hash, V: 'tcx> CacheSelector<K, V> for ArenaCacheSelector<'tc } pub struct ArenaCache<'tcx, K, V> { - arena: WorkerLocal<&'tcx TypedArena<(V, DepNodeIndex)>>, - phantom: PhantomData<K>, + arena: WorkerLocal<TypedArena<(V, DepNodeIndex)>>, + phantom: PhantomData<(K, &'tcx V)>, } impl<'tcx, K, V> Default for ArenaCache<'tcx, K, V> { fn default() -> Self { - ArenaCache { - arena: WorkerLocal::new(|_| &*Box::leak(Box::new(TypedArena::default()))), - phantom: PhantomData, - } + ArenaCache { arena: WorkerLocal::new(|_| TypedArena::default()), phantom: PhantomData } } } @@ -162,7 +159,8 @@ impl<'tcx, K: Eq + Hash, V: 'tcx> QueryStorage for ArenaCache<'tcx, K, V> { fn store_nocache(&self, value: Self::Value) -> Self::Stored { let value = self.arena.alloc((value, DepNodeIndex::INVALID)); - &value.0 + let value = unsafe { &*(&value.0 as *const _) }; + &value } } @@ -204,6 +202,7 @@ impl<'tcx, K: Eq + Hash, V: 'tcx> QueryCache for ArenaCache<'tcx, K, V> { index: DepNodeIndex, ) -> Self::Stored { let value = self.arena.alloc((value, index)); + let value = unsafe { &*(value as *const _) }; lock_sharded_storage.insert(key, value); &value.0 } |
