Skip to content

Commit

Permalink
Stop leaking memory.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Apr 28, 2020
1 parent e56c400 commit 143b881
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/librustc_query_system/query/caches.rs
Expand Up @@ -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 }
}
}

Expand All @@ -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
}
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 143b881

Please sign in to comment.