summaryrefslogtreecommitdiff
path: root/libavcodec/psymodel.c
diff options
context:
space:
mode:
authorVittorio Giovara <vittorio.giovara@gmail.com>2015-05-31 14:54:55 +0200
committerLuca Barbato <lu_zero@gentoo.org>2015-05-31 15:03:31 +0200
commit03927cb73399e6f07185fc7f8851d7612b4187b6 (patch)
treecafaec8f4568dfa822facf12d36d6b318296b2f2 /libavcodec/psymodel.c
parentfef2f4722bcbfe1c3802898b0f5deb6356132c91 (diff)
psymodel: Check memory allocation
Diffstat (limited to 'libavcodec/psymodel.c')
-rw-r--r--libavcodec/psymodel.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/libavcodec/psymodel.c b/libavcodec/psymodel.c
index a2af61175e..5179ede083 100644
--- a/libavcodec/psymodel.c
+++ b/libavcodec/psymodel.c
@@ -39,6 +39,12 @@ av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens,
ctx->group = av_mallocz(sizeof(ctx->group[0]) * num_groups);
ctx->bands = av_malloc (sizeof(ctx->bands[0]) * num_lens);
ctx->num_bands = av_malloc (sizeof(ctx->num_bands[0]) * num_lens);
+
+ if (!ctx->ch || !ctx->group || !ctx->bands || !ctx->num_bands) {
+ ff_psy_end(ctx);
+ return AVERROR(ENOMEM);
+ }
+
memcpy(ctx->bands, bands, sizeof(ctx->bands[0]) * num_lens);
memcpy(ctx->num_bands, num_bands, sizeof(ctx->num_bands[0]) * num_lens);
@@ -98,6 +104,8 @@ av_cold struct FFPsyPreprocessContext* ff_psy_preprocess_init(AVCodecContext *av
int i;
float cutoff_coeff = 0;
ctx = av_mallocz(sizeof(FFPsyPreprocessContext));
+ if (!ctx)
+ return NULL;
ctx->avctx = avctx;
if (avctx->cutoff > 0)
@@ -109,6 +117,10 @@ av_cold struct FFPsyPreprocessContext* ff_psy_preprocess_init(AVCodecContext *av
cutoff_coeff, 0.0, 0.0);
if (ctx->fcoeffs) {
ctx->fstate = av_mallocz(sizeof(ctx->fstate[0]) * avctx->channels);
+ if (!ctx->fstate) {
+ av_free(ctx);
+ return NULL;
+ }
for (i = 0; i < avctx->channels; i++)
ctx->fstate[i] = ff_iir_filter_init_state(FILT_ORDER);
}