Use boxed::into_raw where it makes sense.

This commit is contained in:
Ms2ger 2015-04-07 17:54:16 +02:00
parent dd7ec693a5
commit b5d41aa8a5

View file

@ -32,6 +32,7 @@ use types::{cef_window_info_t, cef_xml_encoding_type_t, cef_xml_node_type_t};
use unicode::str::Utf16Encoder; use unicode::str::Utf16Encoder;
use libc::{self, c_char, c_int, c_ushort, c_void}; use libc::{self, c_char, c_int, c_ushort, c_void};
use std::boxed;
use std::collections::HashMap; use std::collections::HashMap;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
@ -187,14 +188,11 @@ impl<'a> CefWrap<*const cef_string_t> for &'a [u16] {
// FIXME(pcwalton): This leaks!! We should instead have the caller pass some scratch // FIXME(pcwalton): This leaks!! We should instead have the caller pass some scratch
// stack space to create the object in. What a botch. // stack space to create the object in. What a botch.
let boxed_string = box cef_string_utf16 { boxed::into_raw(box cef_string_utf16 {
str: ptr, str: ptr,
length: buffer.len() as u64, length: buffer.len() as u64,
dtor: Some(free_boxed_utf16_string as extern "C" fn(*mut c_ushort)), dtor: Some(free_boxed_utf16_string as extern "C" fn(*mut c_ushort)),
}; }) as *const _
let result: *const cef_string_utf16 = &*boxed_string;
mem::forget(boxed_string);
result
} }
} }
unsafe fn to_rust(cef_string: *const cef_string_t) -> &'a [u16] { unsafe fn to_rust(cef_string: *const cef_string_t) -> &'a [u16] {