diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-02-12 16:51:44 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-02-12 16:56:22 +0100 |
commit | ddcd197113b805410ea273e7e36ab73fe7b13c2c (patch) | |
tree | 70be59466d8c3bdb3b5838e5ab860d1480709e38 /ffi-macros/src/lib.rs | |
parent | 0e1a25c5180046320a811a89901952bd4333954c (diff) |
ffi-macros: Fix freeing wrappers with references.
- We cannot use move_from_raw() here, because there may be no object
to move from raw.
Diffstat (limited to 'ffi-macros/src/lib.rs')
-rw-r--r-- | ffi-macros/src/lib.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/ffi-macros/src/lib.rs b/ffi-macros/src/lib.rs index a71562c1..6f1ce312 100644 --- a/ffi-macros/src/lib.rs +++ b/ffi-macros/src/lib.rs @@ -604,11 +604,24 @@ fn derive_free(span: proc_macro2::Span, prefix: &str, name: &str, quote! { /// Frees this object. #[::sequoia_ffi_macros::extern_fn] #[no_mangle] - pub extern "system" fn #ident (this: Option<&mut #wrapper>) { - use ::MoveFromRaw; - if let Some(ref_) = this { - drop((ref_ as *mut #wrapper).move_from_raw()) + pub extern "system" fn #ident (this: *mut #wrapper) { + if this.is_null() { + return; } + + let mut wrapper = unsafe { + Box::from_raw(this) + }; + wrapper.assert_tag(); + let _o = wrapper.0; + + // Poison the wrapper. + unsafe { + // Overwrite with P. + memsec::memset(this as *mut u8, + 0x50, + ::std::mem::size_of::<#wrapper>()) + }; } } } |