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