partial_free.rs 1.1 KB

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