From ac6ea2ab91dca6d76b25f1c78352e73ca2dd9590 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Fri, 21 Jun 2013 17:03:57 -0700 Subject: [PATCH] Allocate memory using appropriate expected alignment in unit tests. Fixes crashes of test_libvpx on 32-bit Linux. Change-Id: If94e7628a86b788ca26c004861dee2f162e47ed6 --- test/variance_test.cc | 10 ++++++---- test/vp9_subtract_test.cc | 16 ++++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/test/variance_test.cc b/test/variance_test.cc index 5d4eab0..e65054f 100644 --- a/test/variance_test.cc +++ b/test/variance_test.cc @@ -18,6 +18,7 @@ #include "vpx/vpx_integer.h" #include "vpx_config.h" extern "C" { +#include "vpx_mem/vpx_mem.h" #if CONFIG_VP8_ENCODER # include "vp8/common/variance.h" # include "vp8_rtcd.h" @@ -205,17 +206,18 @@ class SubpelVarianceTest : rnd(ACMRandom::DeterministicSeed()); block_size_ = width_ * height_; - src_ = new uint8_t[block_size_]; - sec_ = new uint8_t[block_size_]; + src_ = reinterpret_cast(vpx_memalign(16, block_size_)); + sec_ = reinterpret_cast(vpx_memalign(16, block_size_)); ref_ = new uint8_t[block_size_ + width_ + height_ + 1]; ASSERT_TRUE(src_ != NULL); + ASSERT_TRUE(sec_ != NULL); ASSERT_TRUE(ref_ != NULL); } virtual void TearDown() { - delete[] src_; + vpx_free(src_); delete[] ref_; - delete[] sec_; + vpx_free(sec_); } protected: diff --git a/test/vp9_subtract_test.cc b/test/vp9_subtract_test.cc index 1a62b57..3e5fe8d 100644 --- a/test/vp9_subtract_test.cc +++ b/test/vp9_subtract_test.cc @@ -16,6 +16,7 @@ extern "C" { #include "./vpx_config.h" #include "./vp9_rtcd.h" #include "vp9/common/vp9_blockd.h" +#include "vpx_mem/vpx_mem.h" } typedef void (*subtract_fn_t)(int rows, int cols, @@ -42,9 +43,12 @@ TEST_P(VP9SubtractBlockTest, SimpleSubtract) { bsize = static_cast(static_cast(bsize) + 1)) { const int block_width = 4 << b_width_log2(bsize); const int block_height = 4 << b_height_log2(bsize); - int16_t *diff = new int16_t[block_width * block_height * 2]; - uint8_t *pred = new uint8_t[block_width * block_height * 2]; - uint8_t *src = new uint8_t[block_width * block_height * 2]; + int16_t *diff = reinterpret_cast( + vpx_memalign(16, sizeof(*diff) * block_width * block_height * 2)); + uint8_t *pred = reinterpret_cast( + vpx_memalign(16, block_width * block_height * 2)); + uint8_t *src = reinterpret_cast( + vpx_memalign(16, block_width * block_height * 2)); for (int n = 0; n < 100; n++) { for (int r = 0; r < block_height; ++r) { @@ -80,9 +84,9 @@ TEST_P(VP9SubtractBlockTest, SimpleSubtract) { } } } - delete[] diff; - delete[] pred; - delete[] src; + vpx_free(diff); + vpx_free(pred); + vpx_free(src); } } -- 2.7.4