Fixing memory leak after running test to make it so asan doesn't
complain
Change-Id: I6c7c0f2744e0dd9522c908a547ec314c5e80c8a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/croscomp/+/3805799
Reviewed-by: John Plate <jplate@google.com>
Auto-Submit: Lucas Berthou <berlu@chromium.org>
Tested-by: Lucas Berthou <berlu@chromium.org>
Commit-Queue: John Plate <jplate@google.com>
diff --git a/src/ffi.rs b/src/ffi.rs
index 588f85b..d5c3387 100644
--- a/src/ffi.rs
+++ b/src/ffi.rs
@@ -182,6 +182,20 @@
}
}
+ fn drop(head: &mut wl_list) {
+ unsafe {
+ use crate::ffi::wl_list_empty;
+ use std::convert::TryFrom;
+ while wl_list_empty(head) != 1 {
+ let current = head.next;
+ wl_list::remove(&mut *head.next);
+ let offset : isize = unsafe { isize::try_from(offset_of!(Element<i32>, link)).unwrap() };
+ // Move back to from raw for garbage collection.
+ Box::from_raw(&mut *(((current as isize) - offset) as *mut Element<i32>));
+ }
+ }
+ }
+
fn compare<'a, I, T>(iter: I, array: &'a [T])
where
T: std::fmt::Debug + Copy + Eq,
@@ -210,6 +224,9 @@
iter.next();
let iter = iter.rev();
compare(iter, &[3, 2]);
+
+ // clean up to avoid memory leaks
+ drop(&mut list);
}
}