From 2248e1710a0a22631bbcbe071fc058a59bcefcb5 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 20 Jun 2015 13:38:04 +0200 Subject: [PATCH] Use Box and boxed functions to manage cef_string_list_t memory. --- ports/cef/string_list.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/ports/cef/string_list.rs b/ports/cef/string_list.rs index a9a2dfc5252..2c1d4be17be 100644 --- a/ports/cef/string_list.rs +++ b/ports/cef/string_list.rs @@ -3,6 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use libc::{c_int}; +use std::boxed; use std::mem; use std::slice; use string::cef_string_utf16_set; @@ -18,10 +19,7 @@ fn string_list_to_vec(lt: *mut cef_string_list_t) -> *mut Vec { #[no_mangle] pub extern "C" fn cef_string_list_alloc() -> *mut cef_string_list_t { - unsafe { - let lt: Box> = box vec!(); - mem::transmute(lt) - } + boxed::into_raw(box vec!()) } #[no_mangle] @@ -67,9 +65,8 @@ pub extern "C" fn cef_string_list_clear(lt: *mut cef_string_list_t) { pub extern "C" fn cef_string_list_free(lt: *mut cef_string_list_t) { unsafe { if lt.is_null() { return; } - let v: Box> = mem::transmute(lt); cef_string_list_clear(lt); - drop(v); + drop(Box::from_raw(lt)); } } @@ -79,6 +76,6 @@ pub extern "C" fn cef_string_list_copy(lt: *mut cef_string_list_t) -> *mut cef_s if lt.is_null() { return 0 as *mut cef_string_list_t; } let v = string_list_to_vec(lt); let copy = (*v).clone(); - mem::transmute(box copy) + boxed::into_raw(box copy) } }