remove pointer checks before calling aom_free() The function performs this check. This also may quiet some static analyzer checks. For instance from Coverity: CID 323699 (#1 of 1): Dereference before null check (REVERSE_INULL) check_after_deref: Null-checking vt suggests that it may be null, but it has already been dereferenced on all paths leading to the check. Change-Id: Ie79e4a030c0f1d0d02dc77a0845274d555a5e34d
diff --git a/av1/encoder/context_tree.c b/av1/encoder/context_tree.c index 2bd2d7f..7b8240d 100644 --- a/av1/encoder/context_tree.c +++ b/av1/encoder/context_tree.c
@@ -304,8 +304,6 @@ } void av1_free_sms_tree(ThreadData *td) { - if (td->sms_tree != NULL) { - aom_free(td->sms_tree); - td->sms_tree = NULL; - } + aom_free(td->sms_tree); + td->sms_tree = NULL; }
diff --git a/av1/encoder/encodeframe.c b/av1/encoder/encodeframe.c index 53d3905..6d0490c 100644 --- a/av1/encoder/encodeframe.c +++ b/av1/encoder/encodeframe.c
@@ -1244,7 +1244,7 @@ av1_row_mt_mem_dealloc(cpi); - if (cpi->tile_data != NULL) aom_free(cpi->tile_data); + aom_free(cpi->tile_data); CHECK_MEM_ERROR( cm, cpi->tile_data, aom_memalign(32, tile_cols * tile_rows * sizeof(*cpi->tile_data)));
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c index 9bb9482..9906baf 100644 --- a/av1/encoder/encoder.c +++ b/av1/encoder/encoder.c
@@ -4404,10 +4404,8 @@ fclose(f); - if (ppi->ssim_vars != NULL) { - aom_free(ppi->ssim_vars); - ppi->ssim_vars = NULL; - } + aom_free(ppi->ssim_vars); + ppi->ssim_vars = NULL; } } #endif // CONFIG_INTERNAL_STATS
diff --git a/av1/encoder/encoder_alloc.h b/av1/encoder/encoder_alloc.h index 73c1b5b..15fd075 100644 --- a/av1/encoder/encoder_alloc.h +++ b/av1/encoder/encoder_alloc.h
@@ -27,11 +27,9 @@ static AOM_INLINE void dealloc_context_buffers_ext( MBMIExtFrameBufferInfo *mbmi_ext_info) { - if (mbmi_ext_info->frame_base) { - aom_free(mbmi_ext_info->frame_base); - mbmi_ext_info->frame_base = NULL; - mbmi_ext_info->alloc_size = 0; - } + aom_free(mbmi_ext_info->frame_base); + mbmi_ext_info->frame_base = NULL; + mbmi_ext_info->alloc_size = 0; } static AOM_INLINE void alloc_context_buffers_ext( @@ -67,10 +65,8 @@ if (!is_stat_generation_stage(cpi)) av1_alloc_txb_buf(cpi); - if (cpi->td.mb.mv_costs) { - aom_free(cpi->td.mb.mv_costs); - cpi->td.mb.mv_costs = NULL; - } + aom_free(cpi->td.mb.mv_costs); + cpi->td.mb.mv_costs = NULL; // Avoid the memory allocation of 'mv_costs' for allintra encoding mode. if (cpi->oxcf.kf_cfg.key_freq_max != 0) { CHECK_MEM_ERROR(cm, cpi->td.mb.mv_costs, @@ -226,15 +222,10 @@ release_obmc_buffers(&cpi->td.mb.obmc_buffer); - if (cpi->td.mb.mv_costs) { - aom_free(cpi->td.mb.mv_costs); - cpi->td.mb.mv_costs = NULL; - } - - if (cpi->td.mb.dv_costs) { - aom_free(cpi->td.mb.dv_costs); - cpi->td.mb.dv_costs = NULL; - } + aom_free(cpi->td.mb.mv_costs); + cpi->td.mb.mv_costs = NULL; + aom_free(cpi->td.mb.dv_costs); + cpi->td.mb.dv_costs = NULL; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) { @@ -247,20 +238,14 @@ aom_free(cm->tpl_mvs); cm->tpl_mvs = NULL; - if (cpi->td.pixel_gradient_info) { - aom_free(cpi->td.pixel_gradient_info); - cpi->td.pixel_gradient_info = NULL; - } + aom_free(cpi->td.pixel_gradient_info); + cpi->td.pixel_gradient_info = NULL; - if (cpi->td.src_var_info_of_4x4_sub_blocks) { - aom_free(cpi->td.src_var_info_of_4x4_sub_blocks); - cpi->td.src_var_info_of_4x4_sub_blocks = NULL; - } + aom_free(cpi->td.src_var_info_of_4x4_sub_blocks); + cpi->td.src_var_info_of_4x4_sub_blocks = NULL; - if (cpi->td.vt64x64) { - aom_free(cpi->td.vt64x64); - cpi->td.vt64x64 = NULL; - } + aom_free(cpi->td.vt64x64); + cpi->td.vt64x64 = NULL; av1_free_pmc(cpi->td.firstpass_ctx, av1_num_planes(cm)); cpi->td.firstpass_ctx = NULL; @@ -336,15 +321,11 @@ aom_free(cpi->svc.layer_context); cpi->svc.layer_context = NULL; - if (cpi->consec_zero_mv) { - aom_free(cpi->consec_zero_mv); - cpi->consec_zero_mv = NULL; - } + aom_free(cpi->consec_zero_mv); + cpi->consec_zero_mv = NULL; - if (cpi->src_sad_blk_64x64) { - aom_free(cpi->src_sad_blk_64x64); - cpi->src_sad_blk_64x64 = NULL; - } + aom_free(cpi->src_sad_blk_64x64); + cpi->src_sad_blk_64x64 = NULL; aom_free(cpi->mb_weber_stats); cpi->mb_weber_stats = NULL;
diff --git a/av1/encoder/partition_search.c b/av1/encoder/partition_search.c index be4711a..cf9a994 100644 --- a/av1/encoder/partition_search.c +++ b/av1/encoder/partition_search.c
@@ -5220,7 +5220,7 @@ if (num_configs <= 0) { av1_free_pc_tree_recursive(pc_tree, av1_num_planes(cm), 0, 0, cpi->sf.part_sf.partition_search_type); - if (rdcost != NULL) aom_free(rdcost); + aom_free(rdcost); aom_internal_error(cm->error, AOM_CODEC_ERROR, "Invalid configs."); } verify_write_partition_tree(cpi, pc_tree, bsize, i, mi_row, mi_col);
diff --git a/av1/encoder/ratectrl.c b/av1/encoder/ratectrl.c index 224ddf8..da7b148 100644 --- a/av1/encoder/ratectrl.c +++ b/av1/encoder/ratectrl.c
@@ -2968,10 +2968,8 @@ } if (width != cm->render_width || height != cm->render_height || unscaled_src == NULL || unscaled_last_src == NULL) { - if (cpi->src_sad_blk_64x64) { - aom_free(cpi->src_sad_blk_64x64); - cpi->src_sad_blk_64x64 = NULL; - } + aom_free(cpi->src_sad_blk_64x64); + cpi->src_sad_blk_64x64 = NULL; } if (unscaled_src == NULL || unscaled_last_src == NULL) return; src_y = unscaled_src->y_buffer; @@ -2983,10 +2981,8 @@ last_src_width = unscaled_last_src->y_width; last_src_height = unscaled_last_src->y_height; if (src_width != last_src_width || src_height != last_src_height) { - if (cpi->src_sad_blk_64x64) { - aom_free(cpi->src_sad_blk_64x64); - cpi->src_sad_blk_64x64 = NULL; - } + aom_free(cpi->src_sad_blk_64x64); + cpi->src_sad_blk_64x64 = NULL; return; } rc->high_source_sad = 0; @@ -3406,7 +3402,7 @@ if (rc->prev_coded_width == cm->width && rc->prev_coded_height == cm->height) { rc_scene_detection_onepass_rt(cpi, frame_input); - } else if (cpi->src_sad_blk_64x64) { + } else { aom_free(cpi->src_sad_blk_64x64); cpi->src_sad_blk_64x64 = NULL; }
diff --git a/av1/encoder/svc_layercontext.c b/av1/encoder/svc_layercontext.c index 512e1e6..072b8bd 100644 --- a/av1/encoder/svc_layercontext.c +++ b/av1/encoder/svc_layercontext.c
@@ -70,7 +70,7 @@ lc->actual_num_seg1_blocks = 0; lc->actual_num_seg2_blocks = 0; lc->counter_encode_maxq_scene_change = 0; - if (lc->map) aom_free(lc->map); + aom_free(lc->map); CHECK_MEM_ERROR(cm, lc->map, aom_calloc(mi_rows * mi_cols, sizeof(*lc->map))); } @@ -156,7 +156,7 @@ lc->actual_num_seg1_blocks = 0; lc->actual_num_seg2_blocks = 0; lc->counter_encode_maxq_scene_change = 0; - if (lc->map) aom_free(lc->map); + aom_free(lc->map); CHECK_MEM_ERROR(cm, lc->map, aom_calloc(mi_rows * mi_cols, sizeof(*lc->map))); } @@ -359,7 +359,8 @@ for (int tl = 0; tl < svc->number_temporal_layers; ++tl) { int layer = LAYER_IDS_TO_IDX(sl, tl, svc->number_temporal_layers); LAYER_CONTEXT *const lc = &svc->layer_context[layer]; - if (lc->map) aom_free(lc->map); + aom_free(lc->map); + lc->map = NULL; } } }
diff --git a/av1/encoder/var_based_part.c b/av1/encoder/var_based_part.c index 03e8cfa..fda268f 100644 --- a/av1/encoder/var_based_part.c +++ b/av1/encoder/var_based_part.c
@@ -1547,8 +1547,8 @@ uv_sad[0] < thresh_exit_part_uv && uv_sad[1] < thresh_exit_part_uv) { set_block_size(cpi, mi_row, mi_col, bsize); x->force_zeromv_skip_for_sb = 1; - if (vt2) aom_free(vt2); - if (vt) aom_free(vt); + aom_free(vt2); + aom_free(vt); // Partition shape is set here at SB level. // Exit needs to happen from av1_choose_var_based_partitioning(). return true; @@ -1914,8 +1914,8 @@ ref_frame_partition, mi_col, mi_row, is_small_sb); } - if (vt2) aom_free(vt2); - if (vt) aom_free(vt); + aom_free(vt2); + aom_free(vt); #if CONFIG_COLLECT_COMPONENT_TIMING end_timing(cpi, choose_var_based_partitioning_time); #endif