summaryrefslogtreecommitdiff
path: root/vpx_mem
diff options
context:
space:
mode:
authorUrvang Joshi <urvang@google.com>2016-07-26 12:02:37 -0700
committerJames Zern <jzern@google.com>2016-08-24 19:22:52 -0700
commit28c6207bcdf63a35355d302a6e850bacaf204d75 (patch)
treecb9c03e61831292d48e41225cfa7df083fe3ad52 /vpx_mem
parent69c5ba1910f314984fce725ecef4aa3607dba967 (diff)
downloadlibvpx-28c6207bcdf63a35355d302a6e850bacaf204d75.tar
libvpx-28c6207bcdf63a35355d302a6e850bacaf204d75.tar.gz
libvpx-28c6207bcdf63a35355d302a6e850bacaf204d75.tar.bz2
libvpx-28c6207bcdf63a35355d302a6e850bacaf204d75.zip
vpx_realloc correction.
vpx_realloc was allocating 1 byte more than needed every time. Fixed this, and took this opportunity to do a small refactoring. Change-Id: I38fcb62b698894acbbab43466c1decd12f906789 (cherry picked from aom: 2a876b4 aom_realloc correction.)
Diffstat (limited to 'vpx_mem')
-rw-r--r--vpx_mem/vpx_mem.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/vpx_mem/vpx_mem.c b/vpx_mem/vpx_mem.c
index f17e4a023..daf66276b 100644
--- a/vpx_mem/vpx_mem.c
+++ b/vpx_mem/vpx_mem.c
@@ -19,6 +19,10 @@ static INLINE size_t *GetMallocAddressLocation(void *const mem) {
return ((size_t *)mem) - 1;
}
+static INLINE size_t GetAlignedMallocSize(size_t size, size_t align) {
+ return size + align - 1 + ADDRESS_STORAGE_SIZE;
+}
+
static INLINE void SetActualMallocAddress(void *const mem,
const void *const malloc_addr) {
size_t *const malloc_addr_location = GetMallocAddressLocation(mem);
@@ -32,7 +36,8 @@ static INLINE void *GetActualMallocAddress(void *const mem) {
void *vpx_memalign(size_t align, size_t size) {
void *x = NULL;
- void *const addr = malloc(size + align - 1 + ADDRESS_STORAGE_SIZE);
+ const size_t aligned_size = GetAlignedMallocSize(size, align);
+ void *const addr = malloc(aligned_size);
if (addr) {
x = align_addr((unsigned char *)addr + ADDRESS_STORAGE_SIZE, (int)align);
SetActualMallocAddress(x, addr);
@@ -66,8 +71,9 @@ void *vpx_realloc(void *memblk, size_t size) {
vpx_free(memblk);
else {
void *addr = GetActualMallocAddress(memblk);
+ const size_t aligned_size = GetAlignedMallocSize(size, DEFAULT_ALIGNMENT);
memblk = NULL;
- addr = realloc(addr, size + DEFAULT_ALIGNMENT + ADDRESS_STORAGE_SIZE);
+ addr = realloc(addr, aligned_size);
if (addr) {
new_addr = align_addr((unsigned char *)addr + ADDRESS_STORAGE_SIZE,
DEFAULT_ALIGNMENT);