Skip to content

Commit a33acbe

Browse files
committed
Auto merge of #465 - JustForFun88:fix_bugs_clone_from, r=Amanieu
Fix two bugs in `clone_from` one of which is mine 😅 (was introduced in #458) My bad 😅, I totally forgot that we can modify table from another thread, which can result in an invalid `self` table in case if we have a panic during the cloning of elements (we will have an empty table with invalid control bytes to which we can get accessed via `RawIterRange` during parallel iteration or via the `find` function). This pull request fixes my bug by partially reverting the old implementation of the `clone_from` function. Also fixes leaking allocator when `self_.buckets() != source.buckets`. We used to rewrite the table (`&mut **self_ as *mut Self).write()`), forgetting that although we freed the old table memory, we forgot about the old allocator (**this behavior was found during testing**). Now, to allocate a new table, we use the old allocator, via `ptr::read(&self_.table.alloc)`. The latter is worth thinking about. Maybe instead of using the old allocator, it's better to use the new one via `alloc.clone()` and just drop the old one? **P.S.** Added tests for the cases described above.
2 parents ec75914 + 8a4a1c7 commit a33acbe

File tree

3 files changed

+494
-94
lines changed

3 files changed

+494
-94
lines changed

0 commit comments

Comments
 (0)