mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Use the Box/boxed APIs to handle cef_string_multimap_t memory management.
This commit is contained in:
parent
cb2f7c7496
commit
ccc38ef5a1
1 changed files with 3 additions and 8 deletions
|
@ -4,9 +4,8 @@
|
||||||
|
|
||||||
use eutil::slice_to_str;
|
use eutil::slice_to_str;
|
||||||
use libc::c_int;
|
use libc::c_int;
|
||||||
|
use std::boxed;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::mem;
|
|
||||||
use std::string::String;
|
|
||||||
use string::{cef_string_userfree_utf16_alloc, cef_string_userfree_utf16_free};
|
use string::{cef_string_userfree_utf16_alloc, cef_string_userfree_utf16_free};
|
||||||
use string::{cef_string_utf16_set};
|
use string::{cef_string_utf16_set};
|
||||||
use types::{cef_string_multimap_t,cef_string_t};
|
use types::{cef_string_multimap_t,cef_string_t};
|
||||||
|
@ -15,10 +14,7 @@ use types::{cef_string_multimap_t,cef_string_t};
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn cef_string_multimap_alloc() -> *mut cef_string_multimap_t {
|
pub extern "C" fn cef_string_multimap_alloc() -> *mut cef_string_multimap_t {
|
||||||
unsafe {
|
boxed::into_raw(box BTreeMap::new())
|
||||||
let smm: Box<BTreeMap<String, Vec<*mut cef_string_t>>> = box BTreeMap::new();
|
|
||||||
mem::transmute(smm)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -138,8 +134,7 @@ pub extern "C" fn cef_string_multimap_clear(smm: *mut cef_string_multimap_t) {
|
||||||
pub extern "C" fn cef_string_multimap_free(smm: *mut cef_string_multimap_t) {
|
pub extern "C" fn cef_string_multimap_free(smm: *mut cef_string_multimap_t) {
|
||||||
unsafe {
|
unsafe {
|
||||||
if smm.is_null() { return; }
|
if smm.is_null() { return; }
|
||||||
let v: Box<BTreeMap<String, Vec<*mut cef_string_t>>> = mem::transmute(smm);
|
|
||||||
cef_string_multimap_clear(smm);
|
cef_string_multimap_clear(smm);
|
||||||
drop(v);
|
drop(Box::from_raw(smm));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue