partial_free.rs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. extern crate ralloc;
  2. mod util;
  3. use std::ptr;
  4. #[test]
  5. fn partial_free() {
  6. util::multiply(|| {
  7. let mut alloc = ralloc::Allocator::new();
  8. let buf = alloc.alloc(63, 3);
  9. unsafe {
  10. util::acid(|| {
  11. ptr::write_bytes(buf, 0, 63);
  12. *buf = 4;
  13. });
  14. util::acid(|| {
  15. alloc.free(buf.offset(8), 75);
  16. *buf = 5;
  17. });
  18. util::acid(|| {
  19. alloc.free(buf, 4);
  20. *buf.offset(4) = 3;
  21. });
  22. assert_eq!(*buf.offset(4), 3);
  23. }
  24. });
  25. }
  26. #[test]
  27. fn partial_free_double() {
  28. util::multiply(|| {
  29. let mut alloc = ralloc::Allocator::new();
  30. let buf = alloc.alloc(64, 4);
  31. unsafe {
  32. util::acid(|| {
  33. ptr::write_bytes(buf, 0, 64);
  34. });
  35. util::acid(|| {
  36. alloc.free(buf.offset(32), 32);
  37. *buf = 5;
  38. });
  39. assert_eq!(*buf, 5);
  40. util::acid(|| {
  41. *buf = 0xAA;
  42. alloc.free(buf, 32);
  43. });
  44. }
  45. });
  46. }