diff --git a/ports/cef/string.rs b/ports/cef/string.rs index 19fd8754081..b4ead90f71d 100644 --- a/ports/cef/string.rs +++ b/ports/cef/string.rs @@ -75,7 +75,7 @@ pub extern "C" fn cef_string_utf8_clear(cs: *mut cef_string_utf8_t) { #[no_mangle] pub extern "C" fn cef_string_userfree_utf8_alloc() -> *mut cef_string_utf8_t { unsafe { - libc::malloc(mem::size_of::() as u64) as *mut cef_string_utf8_t + libc::calloc(1, mem::size_of::() as u64) as *mut cef_string_utf8_t } } @@ -85,7 +85,7 @@ pub extern "C" fn cef_string_utf8_set(src: *const u8, src_len: size_t, output: * unsafe { if copy != 0 { if !src.is_null() && src_len > 0 { - (*output).str = libc::malloc(src_len + 1) as *mut u8; + (*output).str = libc::calloc(1, src_len + 1) as *mut u8; if (*output).str.is_null() { return 0; } @@ -156,7 +156,7 @@ pub extern "C" fn cef_string_utf16_clear(cs: *mut cef_string_utf16_t) { #[no_mangle] pub extern "C" fn cef_string_userfree_utf16_alloc() -> *mut cef_string_utf16_t { unsafe { - libc::malloc(mem::size_of::() as u64) as *mut cef_string_utf16_t + libc::calloc(1, mem::size_of::() as u64) as *mut cef_string_utf16_t } } @@ -166,7 +166,7 @@ pub extern "C" fn cef_string_utf16_set(src: *const c_ushort, src_len: size_t, ou unsafe { if copy != 0 { if !src.is_null() && src_len > 0 { - (*output).str = libc::malloc((src_len + 1) * mem::size_of::() as u64) as + (*output).str = libc::calloc(1, (src_len + 1) * mem::size_of::() as u64) as *mut u16; if (*output).str.is_null() { return 0; @@ -214,7 +214,7 @@ pub extern "C" fn cef_string_wide_clear(cs: *mut cef_string_wide_t) { #[no_mangle] pub extern "C" fn cef_string_userfree_wide_alloc() -> *mut cef_string_wide_t { unsafe { - libc::malloc(mem::size_of::() as u64) as *mut cef_string_wide_t + libc::calloc(1, mem::size_of::() as u64) as *mut cef_string_wide_t } } @@ -224,7 +224,7 @@ pub extern "C" fn cef_string_wide_set(src: *const wchar_t, src_len: size_t, outp unsafe { if copy != 0 { if !src.is_null() && src_len > 0 { - (*output).str = libc::malloc((src_len + 1) * mem::size_of::() as u64) as + (*output).str = libc::calloc(1, (src_len + 1) * mem::size_of::() as u64) as *mut wchar_t; if (*output).str.is_null() { return 0; diff --git a/ports/cef/wrappers.rs b/ports/cef/wrappers.rs index d9c2ecee5bc..ae871595743 100644 --- a/ports/cef/wrappers.rs +++ b/ports/cef/wrappers.rs @@ -181,7 +181,8 @@ cef_unimplemented_wrapper!(cef_string_t, String) impl<'a> CefWrap<*const cef_string_t> for &'a [u16] { fn to_c(buffer: &'a [u16]) -> *const cef_string_t { unsafe { - let ptr: *mut c_ushort = mem::transmute(libc::malloc(((buffer.len() * 2) + 1) as u64)); + let ptr: *mut c_ushort = + mem::transmute(libc::calloc(1, ((buffer.len() * 2) + 1) as u64)); ptr::copy_memory(ptr, mem::transmute(buffer.as_ptr()), (buffer.len() * 2) as uint); *ptr.offset(buffer.len() as int) = 0;