From 0132106c7eb7aea4eca71a6dfce41d1e8ec38113 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 28 Jul 2019 17:47:52 +0000 Subject: [PATCH] fix(imex): dc_decrypt_setup_file: extend lifetime of CString payload_c binding makes sure the memory is not freed until strdup exits. See as_ptr documentation: https://doc.rust-lang.org/std/ffi/struct.CString.html#method.as_ptr --- src/dc_imex.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dc_imex.rs b/src/dc_imex.rs index 0a0ff19a8..be13b7aa8 100644 --- a/src/dc_imex.rs +++ b/src/dc_imex.rs @@ -490,7 +490,8 @@ pub unsafe fn dc_decrypt_setup_file( if let Some(plain) = dc_pgp_symm_decrypt(passphrase, binary as *const libc::c_void, binary_bytes) { - payload = strdup(CString::new(plain).unwrap().as_ptr()); + let payload_c = CString::new(plain).unwrap(); + payload = strdup(payload_c.as_ptr()); } } }