summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vp9/common/vp9_postproc.c1
-rw-r--r--vp9/encoder/vp9_bitstream.c15
-rw-r--r--vp9/encoder/vp9_encoder.c6
-rw-r--r--vp9/encoder/vp9_multi_thread.c11
-rw-r--r--vp9/encoder/vp9_non_greedy_mv.c3
-rw-r--r--vp9/encoder/vp9_speed_features.c19
-rw-r--r--vp9/ratectrl_rtc.cc9
-rw-r--r--vp9/simple_encode.cc1
-rw-r--r--vpx_dsp/fastssim.c6
-rw-r--r--y4minput.c8
10 files changed, 52 insertions, 27 deletions
diff --git a/vp9/common/vp9_postproc.c b/vp9/common/vp9_postproc.c
index d2c8535b0..96519f005 100644
--- a/vp9/common/vp9_postproc.c
+++ b/vp9/common/vp9_postproc.c
@@ -360,6 +360,7 @@ int vp9_post_proc_frame(struct VP9Common *cm, YV12_BUFFER_CONFIG *dest,
if (!cm->postproc_state.limits) {
cm->postproc_state.limits =
vpx_calloc(unscaled_width, sizeof(*cm->postproc_state.limits));
+ if (!cm->postproc_state.limits) return 1;
}
}
diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c
index 99cc2ee83..75bd097f2 100644
--- a/vp9/encoder/vp9_bitstream.c
+++ b/vp9/encoder/vp9_bitstream.c
@@ -963,21 +963,20 @@ void vp9_bitstream_encode_tiles_buffer_dealloc(VP9_COMP *const cpi) {
}
}
-static int encode_tiles_buffer_alloc(VP9_COMP *const cpi) {
+static void encode_tiles_buffer_alloc(VP9_COMP *const cpi) {
+ VP9_COMMON *const cm = &cpi->common;
int i;
const size_t worker_data_size =
cpi->num_workers * sizeof(*cpi->vp9_bitstream_worker_data);
- cpi->vp9_bitstream_worker_data = vpx_memalign(16, worker_data_size);
+ CHECK_MEM_ERROR(cm, cpi->vp9_bitstream_worker_data,
+ vpx_memalign(16, worker_data_size));
memset(cpi->vp9_bitstream_worker_data, 0, worker_data_size);
- if (!cpi->vp9_bitstream_worker_data) return 1;
for (i = 1; i < cpi->num_workers; ++i) {
cpi->vp9_bitstream_worker_data[i].dest_size =
cpi->oxcf.width * cpi->oxcf.height;
- cpi->vp9_bitstream_worker_data[i].dest =
- vpx_malloc(cpi->vp9_bitstream_worker_data[i].dest_size);
- if (!cpi->vp9_bitstream_worker_data[i].dest) return 1;
+ CHECK_MEM_ERROR(cm, cpi->vp9_bitstream_worker_data[i].dest,
+ vpx_malloc(cpi->vp9_bitstream_worker_data[i].dest_size));
}
- return 0;
}
static size_t encode_tiles_mt(VP9_COMP *cpi, uint8_t *data_ptr) {
@@ -992,7 +991,7 @@ static size_t encode_tiles_mt(VP9_COMP *cpi, uint8_t *data_ptr) {
cpi->vp9_bitstream_worker_data[1].dest_size >
(cpi->oxcf.width * cpi->oxcf.height)) {
vp9_bitstream_encode_tiles_buffer_dealloc(cpi);
- if (encode_tiles_buffer_alloc(cpi)) return 0;
+ encode_tiles_buffer_alloc(cpi);
}
while (tile_col < tile_cols) {
diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c
index ec6a75619..89b7c8e24 100644
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -3684,9 +3684,9 @@ static void set_size_dependent_vars(VP9_COMP *cpi, int *q, int *bottom_index,
case 6: l = 150; break;
}
if (!cpi->common.postproc_state.limits) {
- cpi->common.postproc_state.limits =
- vpx_calloc(cpi->un_scaled_source->y_width,
- sizeof(*cpi->common.postproc_state.limits));
+ CHECK_MEM_ERROR(cm, cpi->common.postproc_state.limits,
+ vpx_calloc(cpi->un_scaled_source->y_width,
+ sizeof(*cpi->common.postproc_state.limits)));
}
vp9_denoise(&cpi->common, cpi->Source, cpi->Source, l,
cpi->common.postproc_state.limits);
diff --git a/vp9/encoder/vp9_multi_thread.c b/vp9/encoder/vp9_multi_thread.c
index c66c03549..45659f2a9 100644
--- a/vp9/encoder/vp9_multi_thread.c
+++ b/vp9/encoder/vp9_multi_thread.c
@@ -36,7 +36,7 @@ void *vp9_enc_grp_get_next_job(MultiThreadHandle *multi_thread_ctxt,
pthread_mutex_lock(mutex_handle);
#endif
next = job_queue_hdl->next;
- if (NULL != next) {
+ if (next != NULL) {
JobQueue *job_queue = (JobQueue *)next;
job_info = &job_queue->job_info;
// Update the next job in the queue
@@ -58,9 +58,10 @@ void vp9_row_mt_alloc_rd_thresh(VP9_COMP *const cpi,
(mi_cols_aligned_to_sb(cm->mi_rows) >> MI_BLOCK_SIZE_LOG2) + 1;
int i;
- this_tile->row_base_thresh_freq_fact =
+ CHECK_MEM_ERROR(
+ cm, this_tile->row_base_thresh_freq_fact,
(int *)vpx_calloc(sb_rows * BLOCK_SIZES * MAX_MODES,
- sizeof(*(this_tile->row_base_thresh_freq_fact)));
+ sizeof(*(this_tile->row_base_thresh_freq_fact))));
for (i = 0; i < sb_rows * BLOCK_SIZES * MAX_MODES; i++)
this_tile->row_base_thresh_freq_fact[i] = RD_THRESH_INIT_FACT;
}
@@ -84,8 +85,8 @@ void vp9_row_mt_mem_alloc(VP9_COMP *cpi) {
multi_thread_ctxt->allocated_tile_rows = tile_rows;
multi_thread_ctxt->allocated_vert_unit_rows = jobs_per_tile_col;
- multi_thread_ctxt->job_queue =
- (JobQueue *)vpx_memalign(32, total_jobs * sizeof(JobQueue));
+ CHECK_MEM_ERROR(cm, multi_thread_ctxt->job_queue,
+ (JobQueue *)vpx_memalign(32, total_jobs * sizeof(JobQueue)));
#if CONFIG_MULTITHREAD
// Create mutex for each tile
diff --git a/vp9/encoder/vp9_non_greedy_mv.c b/vp9/encoder/vp9_non_greedy_mv.c
index 4679d6c49..d52801c84 100644
--- a/vp9/encoder/vp9_non_greedy_mv.c
+++ b/vp9/encoder/vp9_non_greedy_mv.c
@@ -178,6 +178,7 @@ Status vp9_alloc_motion_field_info(MotionFieldInfo *motion_field_info,
motion_field_info->frame_num = frame_num;
motion_field_info->motion_field_array =
vpx_calloc(frame_num, sizeof(*motion_field_info->motion_field_array));
+ if (!motion_field_info->motion_field_array) return STATUS_FAILED;
for (frame_idx = 0; frame_idx < frame_num; ++frame_idx) {
for (rf_idx = 0; rf_idx < MAX_INTER_REF_FRAMES; ++rf_idx) {
for (square_block_idx = 0; square_block_idx < SQUARE_BLOCK_SIZES;
@@ -422,6 +423,7 @@ void vp9_get_smooth_motion_field(const MV *search_mf,
int row, col;
int bw = 4 << b_width_log2_lookup[bsize];
int bh = 4 << b_height_log2_lookup[bsize];
+ if (!(input && output)) goto fail;
// copy search results to input buffer
for (idx = 0; idx < rows * cols; ++idx) {
input[idx].row = (float)search_mf[idx].row / bh;
@@ -450,6 +452,7 @@ void vp9_get_smooth_motion_field(const MV *search_mf,
smooth_mf[idx].row = (int)(input[idx].row * bh);
smooth_mf[idx].col = (int)(input[idx].col * bw);
}
+fail:
free(input);
free(output);
}
diff --git a/vp9/encoder/vp9_speed_features.c b/vp9/encoder/vp9_speed_features.c
index 7d7b2c3fb..0431d8a45 100644
--- a/vp9/encoder/vp9_speed_features.c
+++ b/vp9/encoder/vp9_speed_features.c
@@ -652,8 +652,10 @@ static void set_rt_speed_feature_framesize_independent(
if (cpi->content_state_sb_fd == NULL &&
(!cpi->use_svc ||
svc->spatial_layer_id == svc->number_spatial_layers - 1)) {
- cpi->content_state_sb_fd = (uint8_t *)vpx_calloc(
- (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1), sizeof(uint8_t));
+ CHECK_MEM_ERROR(cm, cpi->content_state_sb_fd,
+ (uint8_t *)vpx_calloc(
+ (cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
+ sizeof(uint8_t)));
}
}
if (cpi->oxcf.rc_mode == VPX_CBR && content != VP9E_CONTENT_SCREEN) {
@@ -804,14 +806,17 @@ static void set_rt_speed_feature_framesize_independent(
sf->partition_search_type = FIXED_PARTITION;
sf->always_this_block_size = BLOCK_64X64;
}
- if (cpi->count_arf_frame_usage == NULL)
- cpi->count_arf_frame_usage =
+ if (cpi->count_arf_frame_usage == NULL) {
+ CHECK_MEM_ERROR(
+ cm, cpi->count_arf_frame_usage,
(uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
- sizeof(*cpi->count_arf_frame_usage));
+ sizeof(*cpi->count_arf_frame_usage)));
+ }
if (cpi->count_lastgolden_frame_usage == NULL)
- cpi->count_lastgolden_frame_usage =
+ CHECK_MEM_ERROR(
+ cm, cpi->count_lastgolden_frame_usage,
(uint8_t *)vpx_calloc((cm->mi_stride >> 3) * ((cm->mi_rows >> 3) + 1),
- sizeof(*cpi->count_lastgolden_frame_usage));
+ sizeof(*cpi->count_lastgolden_frame_usage)));
}
if (svc->previous_frame_is_intra_only) {
sf->partition_search_type = FIXED_PARTITION;
diff --git a/vp9/ratectrl_rtc.cc b/vp9/ratectrl_rtc.cc
index 76ff367c0..f4d7f7e9e 100644
--- a/vp9/ratectrl_rtc.cc
+++ b/vp9/ratectrl_rtc.cc
@@ -25,7 +25,10 @@ std::unique_ptr<VP9RateControlRTC> VP9RateControlRTC::Create(
VP9RateControlRTC());
if (!rc_api) return nullptr;
rc_api->cpi_ = static_cast<VP9_COMP *>(vpx_memalign(32, sizeof(*cpi_)));
- if (!rc_api->cpi_) return nullptr;
+ if (!rc_api->cpi_) {
+ rc_api.reset();
+ return nullptr;
+ }
vp9_zero(*rc_api->cpi_);
rc_api->InitRateControl(cfg);
@@ -34,6 +37,10 @@ std::unique_ptr<VP9RateControlRTC> VP9RateControlRTC::Create(
cpi->segmentation_map = static_cast<uint8_t *>(
vpx_calloc(cpi->common.mi_rows * cpi->common.mi_cols,
sizeof(*cpi->segmentation_map)));
+ if (!cpi->segmentation_map) {
+ rc_api.reset();
+ return nullptr;
+ }
cpi->cyclic_refresh =
vp9_cyclic_refresh_alloc(cpi->common.mi_rows, cpi->common.mi_cols);
cpi->cyclic_refresh->content_mode = 0;
diff --git a/vp9/simple_encode.cc b/vp9/simple_encode.cc
index 1a0ada119..654699e1b 100644
--- a/vp9/simple_encode.cc
+++ b/vp9/simple_encode.cc
@@ -110,6 +110,7 @@ static VP9_COMP *init_encoder(const VP9EncoderConfig *oxcf,
vpx_img_fmt_t img_fmt) {
VP9_COMP *cpi;
BufferPool *buffer_pool = (BufferPool *)vpx_calloc(1, sizeof(*buffer_pool));
+ if (!buffer_pool) return NULL;
vp9_initialize_enc();
cpi = vp9_create_compressor(oxcf, buffer_pool);
vp9_update_compressor_with_img_fmt(cpi, img_fmt);
diff --git a/vpx_dsp/fastssim.c b/vpx_dsp/fastssim.c
index 6ab6f557e..4d32a02a5 100644
--- a/vpx_dsp/fastssim.c
+++ b/vpx_dsp/fastssim.c
@@ -47,7 +47,7 @@ struct fs_ctx {
unsigned *col_buf;
};
-static void fs_ctx_init(fs_ctx *_ctx, int _w, int _h, int _nlevels) {
+static int fs_ctx_init(fs_ctx *_ctx, int _w, int _h, int _nlevels) {
unsigned char *data;
size_t data_size;
int lw;
@@ -71,6 +71,7 @@ static void fs_ctx_init(fs_ctx *_ctx, int _w, int _h, int _nlevels) {
lh = (lh + 1) >> 1;
}
data = (unsigned char *)malloc(data_size);
+ if (!data) return -1;
_ctx->level = (fs_level *)data;
_ctx->nlevels = _nlevels;
data += _nlevels * sizeof(*_ctx->level);
@@ -95,6 +96,7 @@ static void fs_ctx_init(fs_ctx *_ctx, int _w, int _h, int _nlevels) {
lh = (lh + 1) >> 1;
}
_ctx->col_buf = (unsigned *)data;
+ return 0;
}
static void fs_ctx_clear(fs_ctx *_ctx) { free(_ctx->level); }
@@ -456,7 +458,7 @@ static double calc_ssim(const uint8_t *_src, int _systride, const uint8_t *_dst,
double ret;
int l;
ret = 1;
- fs_ctx_init(&ctx, _w, _h, FS_NLEVELS);
+ if (fs_ctx_init(&ctx, _w, _h, FS_NLEVELS)) return 99.0;
fs_downsample_level0(&ctx, _src, _systride, _dst, _dystride, _w, _h, _bd,
_shift);
for (l = 0; l < FS_NLEVELS - 1; l++) {
diff --git a/y4minput.c b/y4minput.c
index 9a4bdbd7b..7d3c03a7f 100644
--- a/y4minput.c
+++ b/y4minput.c
@@ -1087,9 +1087,15 @@ int y4m_input_open(y4m_input *y4m_ctx, FILE *file, char *skip_buffer,
y4m_ctx->dst_buf = (unsigned char *)malloc(y4m_ctx->dst_buf_sz);
else
y4m_ctx->dst_buf = (unsigned char *)malloc(2 * y4m_ctx->dst_buf_sz);
+ if (!y4m_ctx->dst_buf) return -1;
- if (y4m_ctx->aux_buf_sz > 0)
+ if (y4m_ctx->aux_buf_sz > 0) {
y4m_ctx->aux_buf = (unsigned char *)malloc(y4m_ctx->aux_buf_sz);
+ if (!y4m_ctx->aux_buf) {
+ free(y4m_ctx->dst_buf);
+ return -1;
+ }
+ }
return 0;
}