shithub: libvpx

Download patch

ref: 3063c376009d07ea9ebe6a9cdbf0d75bc5fa0c85
parent: a7456144ce0ab98e015548dd7cda4165ad2a800c
author: Alex Converse <aconverse@google.com>
date: Wed Oct 5 06:51:30 EDT 2016

Remove vpx_realloc()

It only handles the realloc constraint (preserving low elements) by
serendipity, and we don't actually rely on that behavior anyway.
Meanwhile the calls may do extra copying that gets immediately clobbered
by the callers.

Change-Id: I8dfa89e4a81084b084889c27bd272fdf85184e8d

--- a/vp9/common/vp9_frame_buffers.c
+++ b/vp9/common/vp9_frame_buffers.c
@@ -52,14 +52,12 @@
   if (i == int_fb_list->num_internal_frame_buffers) return -1;
 
   if (int_fb_list->int_fb[i].size < min_size) {
-    int_fb_list->int_fb[i].data =
-        (uint8_t *)vpx_realloc(int_fb_list->int_fb[i].data, min_size);
-    if (!int_fb_list->int_fb[i].data) return -1;
-
-    // This memset is needed for fixing valgrind error from C loop filter
+    vpx_free(int_fb_list->int_fb[i].data);
+    // The data must be zeroed to fix a valgrind error from the C loop filter
     // due to access uninitialized memory in frame border. It could be
-    // removed if border is totally removed.
-    memset(int_fb_list->int_fb[i].data, 0, min_size);
+    // skipped if border were totally removed.
+    int_fb_list->int_fb[i].data = (uint8_t *)vpx_calloc(1, min_size);
+    if (!int_fb_list->int_fb[i].data) return -1;
     int_fb_list->int_fb[i].size = min_size;
   }
 
--- a/vp9/vp9_dx_iface.c
+++ b/vp9/vp9_dx_iface.c
@@ -467,8 +467,8 @@
     // as the size of the first intra frame be better? This will
     // avoid too many deallocate and allocate.
     if (frame_worker_data->scratch_buffer_size < data_sz) {
-      frame_worker_data->scratch_buffer =
-          (uint8_t *)vpx_realloc(frame_worker_data->scratch_buffer, data_sz);
+      vpx_free(frame_worker_data->scratch_buffer);
+      frame_worker_data->scratch_buffer = (uint8_t *)vpx_malloc(data_sz);
       if (frame_worker_data->scratch_buffer == NULL) {
         set_error_detail(ctx, "Failed to reallocate scratch buffer");
         return VPX_CODEC_MEM_ERROR;
--- a/vpx_mem/vpx_mem.c
+++ b/vpx_mem/vpx_mem.c
@@ -76,38 +76,6 @@
   return x;
 }
 
-void *vpx_realloc(void *memblk, size_t size) {
-  void *new_addr = NULL;
-
-  /*
-  The realloc() function changes the size of the object pointed to by
-  ptr to the size specified by size, and returns a pointer to the
-  possibly moved block. The contents are unchanged up to the lesser
-  of the new and old sizes. If ptr is null, realloc() behaves like
-  malloc() for the specified size. If size is zero (0) and ptr is
-  not a null pointer, the object pointed to is freed.
-  */
-  if (!memblk)
-    new_addr = vpx_malloc(size);
-  else if (!size)
-    vpx_free(memblk);
-  else {
-    void *addr = get_actual_malloc_address(memblk);
-    const uint64_t aligned_size =
-        get_aligned_malloc_size(size, DEFAULT_ALIGNMENT);
-    if (!check_size_argument_overflow(1, aligned_size)) return NULL;
-
-    addr = realloc(addr, (size_t)aligned_size);
-    if (addr) {
-      new_addr = align_addr((unsigned char *)addr + ADDRESS_STORAGE_SIZE,
-                            DEFAULT_ALIGNMENT);
-      set_actual_malloc_address(new_addr, addr);
-    }
-  }
-
-  return new_addr;
-}
-
 void vpx_free(void *memblk) {
   if (memblk) {
     void *addr = get_actual_malloc_address(memblk);
--- a/vpx_mem/vpx_mem.h
+++ b/vpx_mem/vpx_mem.h
@@ -26,7 +26,6 @@
 void *vpx_memalign(size_t align, size_t size);
 void *vpx_malloc(size_t size);
 void *vpx_calloc(size_t num, size_t size);
-void *vpx_realloc(void *memblk, size_t size);
 void vpx_free(void *memblk);
 
 #if CONFIG_VP9_HIGHBITDEPTH