aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/wma.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-12-19 05:36:20 +0100
committerMichael Niedermayer <michaelni@gmx.at>2014-12-19 05:36:20 +0100
commit8ccfafa7b41b8239cfbbaa5dfd8eea8a300c64be (patch)
treec787802f60916e7a7ea2b2413e22c5546cb712e9 /libavcodec/wma.c
parent8c9a23833daa88bdf08b7e7fbf3a64ab689ad373 (diff)
parent596b5c488fa1d40f114a64d3b73e1863cab073fb (diff)
downloadffmpeg-8ccfafa7b41b8239cfbbaa5dfd8eea8a300c64be.tar.gz
Merge commit '596b5c488fa1d40f114a64d3b73e1863cab073fb'
* commit '596b5c488fa1d40f114a64d3b73e1863cab073fb': wma: check memory allocations and propagate errors Conflicts: libavcodec/wma.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/wma.c')
-rw-r--r--libavcodec/wma.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/libavcodec/wma.c b/libavcodec/wma.c
index 51fda3f22f..841a2be087 100644
--- a/libavcodec/wma.c
+++ b/libavcodec/wma.c
@@ -33,9 +33,9 @@
/* XXX: use same run/length optimization as mpeg decoders */
// FIXME maybe split decode / encode or pass flag
-static av_cold void init_coef_vlc(VLC *vlc, uint16_t **prun_table,
- float **plevel_table, uint16_t **pint_table,
- const CoefVLCTable *vlc_table)
+static av_cold int init_coef_vlc(VLC *vlc, uint16_t **prun_table,
+ float **plevel_table, uint16_t **pint_table,
+ const CoefVLCTable *vlc_table)
{
int n = vlc_table->n;
const uint8_t *table_bits = vlc_table->huffbits;
@@ -51,6 +51,13 @@ static av_cold void init_coef_vlc(VLC *vlc, uint16_t **prun_table,
level_table = av_malloc_array(n, sizeof(uint16_t));
flevel_table = av_malloc_array(n, sizeof(*flevel_table));
int_table = av_malloc_array(n, sizeof(uint16_t));
+ if (!run_table || !level_table || !flevel_table || !int_table) {
+ av_freep(&run_table);
+ av_freep(&level_table);
+ av_freep(&flevel_table);
+ av_freep(&int_table);
+ return AVERROR(ENOMEM);
+ }
i = 2;
level = 1;
k = 0;
@@ -69,12 +76,14 @@ static av_cold void init_coef_vlc(VLC *vlc, uint16_t **prun_table,
*plevel_table = flevel_table;
*pint_table = int_table;
av_free(level_table);
+
+ return 0;
}
av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
{
WMACodecContext *s = avctx->priv_data;
- int i;
+ int i, ret;
float bps1, high_freq;
volatile float bps;
int sample_rate1;
@@ -346,12 +355,13 @@ av_cold int ff_wma_init(AVCodecContext *avctx, int flags2)
}
s->coef_vlcs[0] = &coef_vlcs[coef_vlc_table * 2];
s->coef_vlcs[1] = &coef_vlcs[coef_vlc_table * 2 + 1];
- init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0],
- &s->int_table[0], s->coef_vlcs[0]);
- init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1],
- &s->int_table[1], s->coef_vlcs[1]);
+ ret = init_coef_vlc(&s->coef_vlc[0], &s->run_table[0], &s->level_table[0],
+ &s->int_table[0], s->coef_vlcs[0]);
+ if (ret < 0)
+ return ret;
- return 0;
+ return init_coef_vlc(&s->coef_vlc[1], &s->run_table[1], &s->level_table[1],
+ &s->int_table[1], s->coef_vlcs[1]);
}
int ff_wma_total_gain_to_bits(int total_gain)