From 5d493143cd826e035c5b0e18a1893d4d1d859f1d Mon Sep 17 00:00:00 2001 From: hui su Date: Mon, 8 May 2017 12:06:12 -0700 Subject: [PATCH] Palette: avoid memory leak with encoder buffers For multi-thread encoding, previously the encoder buffers are allocated at every frame, but only freed at the end of encoding, causing memory leaks. Change-Id: Id0e9d7fba8330e82be9cec1d42b7d4b017b8d772 --- av1/encoder/encoder.c | 2 +- av1/encoder/encoder.h | 4 ++++ av1/encoder/ethread.c | 17 +++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c index 322fa274b..021ca1cc0 100644 --- a/av1/encoder/encoder.c +++ b/av1/encoder/encoder.c @@ -2633,7 +2633,7 @@ void av1_remove_compressor(AV1_COMP *cpi) { if (t < cpi->num_workers - 1) { #if CONFIG_PALETTE if (cpi->common.allow_screen_content_tools) - aom_free(thread_data->td->mb.palette_buffer); + aom_free(thread_data->td->palette_buffer); #endif // CONFIG_PALETTE aom_free(thread_data->td->counts); av1_free_pc_tree(thread_data->td); diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h index 40668df4d..bac468fe5 100644 --- a/av1/encoder/encoder.h +++ b/av1/encoder/encoder.h @@ -324,6 +324,10 @@ typedef struct ThreadData { VAR_TREE *var_tree; VAR_TREE *var_root[MAX_MIB_SIZE_LOG2 - MIN_MIB_SIZE_LOG2 + 1]; + +#if CONFIG_PALETTE + PALETTE_BUFFER *palette_buffer; +#endif // CONFIG_PALETTE } ThreadData; struct EncWorkerData; diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c index 34f0b9566..deef423bf 100644 --- a/av1/encoder/ethread.c +++ b/av1/encoder/ethread.c @@ -101,6 +101,15 @@ void av1_encode_tiles_mt(AV1_COMP *cpi) { CHECK_MEM_ERROR(cm, thread_data->td->counts, aom_calloc(1, sizeof(*thread_data->td->counts))); +#if CONFIG_PALETTE + // Allocate buffers used by palette coding mode. + if (cpi->common.allow_screen_content_tools) { + CHECK_MEM_ERROR( + cm, thread_data->td->palette_buffer, + aom_memalign(16, sizeof(*thread_data->td->palette_buffer))); + } +#endif // CONFIG_PALETTE + // Create threads if (!winterface->reset(worker)) aom_internal_error(&cm->error, AOM_CODEC_ERROR, @@ -134,12 +143,8 @@ void av1_encode_tiles_mt(AV1_COMP *cpi) { } #if CONFIG_PALETTE - // Allocate buffers used by palette coding mode. - if (cpi->common.allow_screen_content_tools && i < num_workers - 1) { - MACROBLOCK *x = &thread_data->td->mb; - CHECK_MEM_ERROR(cm, x->palette_buffer, - aom_memalign(16, sizeof(*x->palette_buffer))); - } + if (cpi->common.allow_screen_content_tools && i < num_workers - 1) + thread_data->td->mb.palette_buffer = thread_data->td->palette_buffer; #endif // CONFIG_PALETTE } -- GitLab