servo: Merge #4136 - ports/cef: Replace calls to malloc with calloc (from pcwalton:cef-calloc); r=metajack
authorPatrick Walton <pcwalton@mimiga.net>
Tue, 02 Dec 2014 14:39:51 -0700
changeset 381993 ce184dddd3355b6d0802cada9635719e4e46f035
parent 381992 2261dc57702102d8688bc6afb1e38e1b38d2e66a
child 381994 b70252bf14882fe2532e337c550e3ffa501e59df
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmetajack
servo: Merge #4136 - ports/cef: Replace calls to malloc with calloc (from pcwalton:cef-calloc); r=metajack r? @metajack Source-Repo: https://github.com/servo/servo Source-Revision: 791606bde79cf38ae8484882a7986a1f258957a4
servo/ports/cef/string.rs
servo/ports/cef/wrappers.rs
--- a/servo/ports/cef/string.rs
+++ b/servo/ports/cef/string.rs
@@ -70,27 +70,27 @@ pub extern "C" fn cef_string_utf8_clear(
         (*cs).dtor = mem::transmute(0 as *const u8);
     }
 }
 
 #[inline(never)]
 #[no_mangle]
 pub extern "C" fn cef_string_userfree_utf8_alloc() -> *mut cef_string_utf8_t {
     unsafe {
-        libc::malloc(mem::size_of::<cef_string_utf8_t>() as u64) as *mut cef_string_utf8_t
+        libc::calloc(1, mem::size_of::<cef_string_utf8_t>() as u64) as *mut cef_string_utf8_t
     }
 }
 
 #[no_mangle]
 pub extern "C" fn cef_string_utf8_set(src: *const u8, src_len: size_t, output: *mut cef_string_utf8_t, copy: c_int) -> c_int {
     cef_string_utf8_clear(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;
              }
 
              ptr::copy_memory((*output).str, src, src_len as uint);
              (*output).length = src_len;
              (*output).dtor = Some(string_utf8_dtor);
            }
@@ -151,27 +151,27 @@ pub extern "C" fn cef_string_utf16_clear
         (*cs).dtor = mem::transmute(0 as *const u8);
     }
 }
 
 #[inline(never)]
 #[no_mangle]
 pub extern "C" fn cef_string_userfree_utf16_alloc() -> *mut cef_string_utf16_t {
     unsafe {
-        libc::malloc(mem::size_of::<cef_string_utf16_t>() as u64) as *mut cef_string_utf16_t
+        libc::calloc(1, mem::size_of::<cef_string_utf16_t>() as u64) as *mut cef_string_utf16_t
     }
 }
 
 #[no_mangle]
 pub extern "C" fn cef_string_utf16_set(src: *const c_ushort, src_len: size_t, output: *mut cef_string_utf16_t, copy: c_int) -> c_int {
     cef_string_utf16_clear(output);
     unsafe {
        if copy != 0 {
            if !src.is_null() && src_len > 0 {
-             (*output).str = libc::malloc((src_len + 1) * mem::size_of::<c_ushort>() as u64) as
+             (*output).str = libc::calloc(1, (src_len + 1) * mem::size_of::<c_ushort>() as u64) as
                  *mut u16;
              if (*output).str.is_null() {
                  return 0;
              }
 
              ptr::copy_memory((*output).str, src, src_len as uint);
              (*output).length = src_len;
              (*output).dtor = Some(string_utf16_dtor);
@@ -209,27 +209,27 @@ pub extern "C" fn cef_string_wide_clear(
         (*cs).dtor = mem::transmute(0 as *const u8);
     }
 }
 
 #[inline(never)]
 #[no_mangle]
 pub extern "C" fn cef_string_userfree_wide_alloc() -> *mut cef_string_wide_t {
     unsafe {
-        libc::malloc(mem::size_of::<cef_string_wide_t>() as u64) as *mut cef_string_wide_t
+        libc::calloc(1, mem::size_of::<cef_string_wide_t>() as u64) as *mut cef_string_wide_t
     }
 }
 
 #[no_mangle]
 pub extern "C" fn cef_string_wide_set(src: *const wchar_t, src_len: size_t, output: *mut cef_string_wide_t, copy: c_int) -> c_int {
     cef_string_wide_clear(output);
     unsafe {
        if copy != 0 {
            if !src.is_null() && src_len > 0 {
-             (*output).str = libc::malloc((src_len + 1) * mem::size_of::<wchar_t>() as u64) as
+             (*output).str = libc::calloc(1, (src_len + 1) * mem::size_of::<wchar_t>() as u64) as
                  *mut wchar_t;
              if (*output).str.is_null() {
                  return 0;
              }
 
              ptr::copy_memory((*output).str, src, src_len as uint);
              (*output).length = src_len;
              (*output).dtor = Some(string_wide_dtor);
--- a/servo/ports/cef/wrappers.rs
+++ b/servo/ports/cef/wrappers.rs
@@ -176,17 +176,18 @@ cef_unimplemented_wrapper!(*mut *mut cef
 cef_unimplemented_wrapper!(cef_string_list_t, Vec<String>)
 cef_unimplemented_wrapper!(cef_string_map_t, HashMap<String,String>)
 cef_unimplemented_wrapper!(cef_string_multimap_t, HashMap<String,Vec<String>>)
 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;
 
             // FIXME(pcwalton): This leaks!! We should instead have the caller pass some scratch
             // stack space to create the object in. What a botch.
             let boxed_string = box cef_string_utf16 {
                 str: ptr,
                 length: buffer.len() as u64,