From 7f7844caad173e39766e7792ccc7b3676768ce63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arttu=20Yl=C3=A4-Outinen?= Date: Tue, 7 Feb 2017 12:57:28 +0900 Subject: [PATCH] Fix finalizing uninitialized encoder states Finalization functions for frame and tile encoder states accessed the frame and tile fields of the encoder state even though they might be NULL. This is the case when the initialization of an encoder state fails. Fixed by adding NULL checks. --- src/encoder_state-ctors_dtors.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/encoder_state-ctors_dtors.c b/src/encoder_state-ctors_dtors.c index 9e4e27c6..ff251bc1 100644 --- a/src/encoder_state-ctors_dtors.c +++ b/src/encoder_state-ctors_dtors.c @@ -61,6 +61,8 @@ static int encoder_state_config_frame_init(encoder_state_t * const state) { } static void encoder_state_config_frame_finalize(encoder_state_t * const state) { + if (state->frame == NULL) return; + kvz_image_list_destroy(state->frame->ref); FREE_POINTER(state->frame->lcu_stats); } @@ -128,6 +130,8 @@ static int encoder_state_config_tile_init(encoder_state_t * const state, } static void encoder_state_config_tile_finalize(encoder_state_t * const state) { + if (state->tile == NULL) return; + if (state->tile->hor_buf_before_sao) kvz_yuv_t_free(state->tile->hor_buf_before_sao); kvz_yuv_t_free(state->tile->hor_buf_search); @@ -160,10 +164,6 @@ static int encoder_state_config_slice_init(encoder_state_t * const state, return 1; } -static void encoder_state_config_slice_finalize(encoder_state_t * const state) { - //Nothing to do (yet?) -} - static int encoder_state_config_wfrow_init(encoder_state_t * const state, const int lcu_offset_y) { @@ -171,10 +171,6 @@ static int encoder_state_config_wfrow_init(encoder_state_t * const state, return 1; } -static void encoder_state_config_wfrow_finalize(encoder_state_t * const state) { - //Nothing to do (yet?) -} - #ifdef KVZ_DEBUG_PRINT_THREADING_INFO static void encoder_state_dump_graphviz(const encoder_state_t * const state) { int i; @@ -692,12 +688,10 @@ void kvz_encoder_state_finalize(encoder_state_t * const state) { state->lcu_order_count = 0; if (!state->parent || (state->parent->wfrow != state->wfrow)) { - encoder_state_config_wfrow_finalize(state); FREE_POINTER(state->wfrow); } if (!state->parent || (state->parent->slice != state->slice)) { - encoder_state_config_slice_finalize(state); FREE_POINTER(state->slice); }