Commit 7f094f10 authored by Alex Converse's avatar Alex Converse
Browse files

Remove aom_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.

Cherry-pick from libvpx:
3063c3760 Remove vpx_realloc()

Change-Id: I8dfa89e4a81084b084889c27bd272fdf85184e8d
parent 232e3847
......@@ -57,36 +57,6 @@ void *aom_calloc(size_t num, size_t size) {
return x;
}
void *aom_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 = aom_malloc(size);
else if (!size)
aom_free(memblk);
else {
void *addr = GetActualMallocAddress(memblk);
const size_t aligned_size = GetAlignedMallocSize(size, DEFAULT_ALIGNMENT);
memblk = NULL;
addr = realloc(addr, aligned_size);
if (addr) {
new_addr = align_addr((unsigned char *)addr + ADDRESS_STORAGE_SIZE,
DEFAULT_ALIGNMENT);
SetActualMallocAddress(new_addr, addr);
}
}
return new_addr;
}
void aom_free(void *memblk) {
if (memblk) {
void *addr = GetActualMallocAddress(memblk);
......
......@@ -27,7 +27,6 @@ extern "C" {
void *aom_memalign(size_t align, size_t size);
void *aom_malloc(size_t size);
void *aom_calloc(size_t num, size_t size);
void *aom_realloc(void *memblk, size_t size);
void aom_free(void *memblk);
#if CONFIG_AOM_HIGHBITDEPTH
......
......@@ -514,8 +514,8 @@ static aom_codec_err_t decode_one(aom_codec_alg_priv_t *ctx,
// 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 *)aom_realloc(frame_worker_data->scratch_buffer, data_sz);
aom_free(frame_worker_data->scratch_buffer);
frame_worker_data->scratch_buffer = (uint8_t *)aom_malloc(data_sz);
if (frame_worker_data->scratch_buffer == NULL) {
set_error_detail(ctx, "Failed to reallocate scratch buffer");
return AOM_CODEC_MEM_ERROR;
......
......@@ -95,9 +95,9 @@ void av1_alloc_restoration_buffers(AV1_COMMON *cm) {
av1_alloc_restoration_struct(
cm, &cm->rst_info[p], ROUND_POWER_OF_TWO(cm->width, cm->subsampling_x),
ROUND_POWER_OF_TWO(cm->height, cm->subsampling_y));
CHECK_MEM_ERROR(
cm, cm->rst_internal.tmpbuf,
(int32_t *)aom_realloc(cm->rst_internal.tmpbuf, RESTORATION_TMPBUF_SIZE));
aom_free(cm->rst_internal.tmpbuf);
CHECK_MEM_ERROR(cm, cm->rst_internal.tmpbuf,
(int32_t *)aom_malloc(RESTORATION_TMPBUF_SIZE));
}
void av1_free_restoration_buffers(AV1_COMMON *cm) {
......
......@@ -53,14 +53,12 @@ int av1_get_frame_buffer(void *cb_priv, size_t min_size,
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 *)aom_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
aom_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 *)aom_calloc(1, min_size);
if (!int_fb_list->int_fb[i].data) return -1;
int_fb_list->int_fb[i].size = min_size;
}
......
......@@ -59,23 +59,23 @@ typedef void (*restore_func_highbd_type)(uint8_t *data8, int width, int height,
int av1_alloc_restoration_struct(AV1_COMMON *cm, RestorationInfo *rst_info,
int width, int height) {
const int ntiles = av1_get_rest_ntiles(width, height, NULL, NULL, NULL, NULL);
aom_free(rst_info->restoration_type);
CHECK_MEM_ERROR(cm, rst_info->restoration_type,
(RestorationType *)aom_realloc(
rst_info->restoration_type,
(RestorationType *)aom_malloc(
sizeof(*rst_info->restoration_type) * ntiles));
aom_free(rst_info->wiener_info);
CHECK_MEM_ERROR(
cm, rst_info->wiener_info,
(WienerInfo *)aom_memalign(16, sizeof(*rst_info->wiener_info) * ntiles));
memset(rst_info->wiener_info, 0, sizeof(*rst_info->wiener_info) * ntiles);
aom_free(rst_info->sgrproj_info);
CHECK_MEM_ERROR(
cm, rst_info->sgrproj_info,
(SgrprojInfo *)aom_realloc(rst_info->sgrproj_info,
sizeof(*rst_info->sgrproj_info) * ntiles));
(SgrprojInfo *)aom_malloc(sizeof(*rst_info->sgrproj_info) * ntiles));
#if USE_DOMAINTXFMRF
aom_free(rst_info->domaintxfmrf_info);
CHECK_MEM_ERROR(cm, rst_info->domaintxfmrf_info,
(DomaintxfmrfInfo *)aom_realloc(
rst_info->domaintxfmrf_info,
(DomaintxfmrfInfo *)aom_malloc(
sizeof(*rst_info->domaintxfmrf_info) * ntiles));
#endif // USE_DOMAINTXFMRF
return ntiles;
......
......@@ -745,8 +745,9 @@ static void alloc_util_frame_buffers(AV1_COMP *cpi) {
"Failed to allocate trial restored frame buffer");
int extra_rstbuf_sz = RESTORATION_EXTBUF_SIZE;
if (extra_rstbuf_sz > 0) {
aom_free(cpi->extra_rstbuf);
CHECK_MEM_ERROR(cm, cpi->extra_rstbuf,
(uint8_t *)aom_realloc(cpi->extra_rstbuf, extra_rstbuf_sz));
(uint8_t *)aom_malloc(extra_rstbuf_sz));
} else {
cpi->extra_rstbuf = NULL;
}
......
......@@ -725,9 +725,13 @@ int av1_has_high_freq_in_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane) {
void add_pvq_block(AV1_COMMON *const cm, MACROBLOCK *const x, PVQ_INFO *pvq) {
PVQ_QUEUE *q = x->pvq_q;
if (q->curr_pos >= q->buf_len) {
q->buf_len = 2 * q->buf_len + 1;
CHECK_MEM_ERROR(cm, q->buf,
aom_realloc(q->buf, q->buf_len * sizeof(PVQ_INFO)));
int new_buf_len = 2 * q->buf_len + 1;
PVQ_INFO *new_buf;
CHECK_MEM_ERROR(cm, new_buf, aom_malloc(new_buf_len * sizeof(PVQ_INFO)));
memcpy(new_buf, q->buf, q->buf_len * sizeof(PVQ_INFO));
aom_free(q->buf);
q->buf = new_buf;
q->buf_len = new_buf_len;
}
// memcpy(q->buf + q->curr_pos, pvq, sizeof(PVQ_INFO));
OD_COPY(q->buf + q->curr_pos, pvq, 1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment