From 6bfcddad735cfd9d3f3c1c128d3c9300c15b3def Mon Sep 17 00:00:00 2001 From: Ohad Ravid Date: Tue, 27 Aug 2024 22:09:53 +0300 Subject: [PATCH] To be safe, clone and leak the `BSTR` --- src/variant.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/variant.rs b/src/variant.rs index 996e25b..4a7c652 100644 --- a/src/variant.rs +++ b/src/variant.rs @@ -104,7 +104,10 @@ impl Variant { let variant_value = match VARENUM(variant_type) { VT_BSTR => { let bstr_ptr = unsafe { BSTR::from_raw(vt.Anonymous.Anonymous.Anonymous.bstrVal) }; - Variant::String(bstr_ptr.try_into()?) + let bstr_as_str = bstr_ptr.to_string(); + // We don't want to be the ones freeing the BSTR. + let _ = bstr_ptr.into_raw(); + Variant::String(bstr_as_str) } VT_I1 => { let num = unsafe { vt.Anonymous.Anonymous.Anonymous.cVal };