aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2013-05-12 12:14:33 +0000
committerPaul B Mahol <onemda@gmail.com>2013-05-12 12:14:33 +0000
commitd93bc4ef5c1729fde4ae9d172e57c2dd928ad5fe (patch)
tree364051cbef2e4c0371224168a66b060e686c1140
parent87888c043da9da407b3c601c47089163ff0e78d8 (diff)
downloadffmpeg-d93bc4ef5c1729fde4ae9d172e57c2dd928ad5fe.tar.gz
redspark: fix memleak in redspark_read_header
Signed-off-by: Paul B Mahol <onemda@gmail.com>
-rw-r--r--libavformat/redspark.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/libavformat/redspark.c b/libavformat/redspark.c
index f98c1156ed..44d5da77fb 100644
--- a/libavformat/redspark.c
+++ b/libavformat/redspark.c
@@ -57,7 +57,7 @@ static int redspark_read_header(AVFormatContext *s)
RedSparkContext *redspark = s->priv_data;
AVCodecContext *codec;
GetByteContext gbc;
- int i, coef_off;
+ int i, coef_off, ret = 0;
uint32_t key, data;
uint8_t *header, *pbc;
AVStream *st;
@@ -67,7 +67,7 @@ static int redspark_read_header(AVFormatContext *s)
return AVERROR(ENOMEM);
codec = st->codec;
- header = av_malloc(HEADER_SIZE);
+ header = av_malloc(HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE);
if (!header)
return AVERROR(ENOMEM);
pbc = header;
@@ -91,15 +91,18 @@ static int redspark_read_header(AVFormatContext *s)
codec->sample_rate = bytestream2_get_be32u(&gbc);
if (codec->sample_rate <= 0 || codec->sample_rate > 96000) {
av_log(s, AV_LOG_ERROR, "Invalid sample rate: %d\n", codec->sample_rate);
- return AVERROR_INVALIDDATA;
+ ret = AVERROR_INVALIDDATA;
+ goto fail;
}
st->duration = bytestream2_get_be32u(&gbc) * 14;
redspark->samples_count = 0;
bytestream2_skipu(&gbc, 10);
codec->channels = bytestream2_get_byteu(&gbc);
- if (!codec->channels)
- return AVERROR_INVALIDDATA;
+ if (!codec->channels) {
+ ret = AVERROR_INVALIDDATA;
+ goto fail;
+ }
coef_off = 0x54 + codec->channels * 8;
if (bytestream2_get_byteu(&gbc)) // Loop flag
@@ -107,20 +110,27 @@ static int redspark_read_header(AVFormatContext *s)
codec->extradata_size = 32 * codec->channels;
codec->extradata = av_malloc(codec->extradata_size);
- if (!codec->extradata)
- return AVERROR(ENOMEM);
+ if (!codec->extradata) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
/* Get the ADPCM table */
bytestream2_seek(&gbc, coef_off, SEEK_SET);
for (i = 0; i < codec->channels; i++) {
- if (bytestream2_get_bufferu(&gbc, codec->extradata + i * 32, 32) != 32)
- return AVERROR_INVALIDDATA;
+ if (bytestream2_get_bufferu(&gbc, codec->extradata + i * 32, 32) != 32) {
+ ret = AVERROR_INVALIDDATA;
+ goto fail;
+ }
bytestream2_skipu(&gbc, 14);
}
avpriv_set_pts_info(st, 64, 1, codec->sample_rate);
- return 0;
+fail:
+ av_free(header);
+
+ return ret;
}
static int redspark_read_packet(AVFormatContext *s, AVPacket *pkt)