diff options
Diffstat (limited to 'ffi')
-rw-r--r-- | ffi/src/core.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ffi/src/core.rs b/ffi/src/core.rs index d0dd5138..a24c2137 100644 --- a/ffi/src/core.rs +++ b/ffi/src/core.rs @@ -61,6 +61,16 @@ impl Context { } } +impl Drop for Context { + fn drop(&mut self) { + if !self.e.is_null() { + unsafe { + drop(Box::from_raw(self.e)); + } + } + } +} + /// Returns the last error. /// /// Returns and removes the last error from the context. @@ -173,3 +183,19 @@ fn sq_config_ephemeral(cfg: *mut Config) { let cfg = ffi_param_ref_mut!(cfg); cfg.set_ephemeral(); } + +#[test] +fn test_drop_context() { + { + use crate::MoveIntoRaw; + + let c = sq_context_new(None); + let ctx = ffi_param_ref_mut!(c); + let errp = ctx.errp(); + { + let e = anyhow::anyhow!("bad"); + *errp = e.move_into_raw(); + } + sq_context_free(Some(ctx)); + } +} |