From d947d2478a5c6dae5acbbe136585c89ec9ef41bf Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Wed, 23 Sep 2020 18:43:46 -0700 Subject: [PATCH] Fix memory leak in archetype resizing Though we properly drop the components themselves, the underlying memory was not recovered. --- src/archetype.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/archetype.rs b/src/archetype.rs index 472c41a3..1f8a9c7c 100644 --- a/src/archetype.rs +++ b/src/archetype.rs @@ -211,6 +211,13 @@ impl Archetype { ty.layout.size() * old_count, ); } + dealloc( + (*self.data.get()).as_ptr().cast(), + Layout::from_size_align_unchecked( + old_data_size, + self.types.first().map_or(1, |x| x.layout.align()), + ), + ); } self.data = UnsafeCell::new(new_data);