summaryrefslogtreecommitdiff
path: root/libavcodec/ffv1.c
diff options
context:
space:
mode:
authorVittorio Giovara <vittorio.giovara@gmail.com>2015-04-09 23:37:59 +0200
committerDiego Biurrun <diego@biurrun.de>2015-04-13 17:51:31 +0200
commit73dacabfc9b9ef1fd2c08105fdab6238ee29c2fc (patch)
treec674722c98e8463b9d39a3e3db1dc4aeacb2fdc2 /libavcodec/ffv1.c
parent4e5443216445f3a9b8e6cb3fa4f448762e19006e (diff)
ffv1: Check memory allocations
Signed-off-by: Diego Biurrun <diego@biurrun.de>
Diffstat (limited to 'libavcodec/ffv1.c')
-rw-r--r--libavcodec/ffv1.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index d1a6a83b13..689cd32d74 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -187,7 +187,7 @@ int ffv1_init_slice_state(FFV1Context *f, FFV1Context *fs)
av_cold int ffv1_init_slice_contexts(FFV1Context *f)
{
- int i;
+ int i, j;
f->slice_count = f->num_h_slices * f->num_v_slices;
if (f->slice_count <= 0) {
@@ -196,13 +196,16 @@ av_cold int ffv1_init_slice_contexts(FFV1Context *f)
}
for (i = 0; i < f->slice_count; i++) {
- FFV1Context *fs = av_mallocz(sizeof(*fs));
int sx = i % f->num_h_slices;
int sy = i / f->num_h_slices;
int sxs = f->avctx->width * sx / f->num_h_slices;
int sxe = f->avctx->width * (sx + 1) / f->num_h_slices;
int sys = f->avctx->height * sy / f->num_v_slices;
int sye = f->avctx->height * (sy + 1) / f->num_v_slices;
+ FFV1Context *fs = av_mallocz(sizeof(*fs));
+ if (!fs)
+ goto memfail;
+
f->slice_context[i] = fs;
memcpy(fs, f, sizeof(*fs));
memset(fs->rc_stat2, 0, sizeof(fs->rc_stat2));
@@ -214,10 +217,19 @@ av_cold int ffv1_init_slice_contexts(FFV1Context *f)
fs->sample_buffer = av_malloc(3 * MAX_PLANES * (fs->width + 6) *
sizeof(*fs->sample_buffer));
- if (!fs->sample_buffer)
- return AVERROR(ENOMEM);
+ if (!fs->sample_buffer) {
+ av_free(fs);
+ goto memfail;
+ }
}
return 0;
+
+memfail:
+ for (j = 0; j < i; j++) {
+ av_free(&f->slice_context[j]->sample_buffer);
+ av_free(&f->slice_context[j]);
+ }
+ return AVERROR(ENOMEM);
}
int ffv1_allocate_initial_states(FFV1Context *f)