File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -24,17 +24,29 @@ pub struct Heap {
2424
2525impl Drop for Heap {
2626 fn drop ( & mut self ) {
27- unsafe {
28- let layout = alloc:: Layout :: array :: < u8 > ( self . inner . byte_cap ) . unwrap ( ) ;
29- alloc:: dealloc ( self . inner . ptr , layout) ;
27+ if !self . inner . ptr . is_null ( ) {
28+ unsafe {
29+ let layout = alloc:: Layout :: array :: < u8 > ( self . inner . byte_cap ) . unwrap ( ) ;
30+ alloc:: dealloc ( self . inner . ptr , layout) ;
31+ }
3032 }
3133 }
3234}
3335
36+ // TODO: verify the soundness of the various accesses to `ptr`,
37+ // or rely on a Vec-like library with fallible allocations.
3438#[ derive( Debug ) ]
3539struct InnerHeap {
3640 ptr : * mut u8 ,
41+
42+ /// # Safety
43+ ///
44+ /// Must be equal to zero when `ptr.is_null()`.
3745 byte_len : usize ,
46+
47+ /// # Safety
48+ ///
49+ /// Must be equal to zero when `ptr.is_null()`.
3850 byte_cap : usize ,
3951}
4052
You can’t perform that action at this time.
0 commit comments