aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <nfxjfg@googlemail.com>2015-01-09 21:24:54 +0100
committerMichael Niedermayer <michaelni@gmx.at>2015-01-10 00:26:43 +0100
commitaab74a38b8ba910a383dd82953061d5c42772ae9 (patch)
tree59f559b1b1e71f326960c50b8141d412abe26e5b
parent11d8fa5e9d695fc3f9f553dc313edd9d4e45ed18 (diff)
downloadffmpeg-aab74a38b8ba910a383dd82953061d5c42772ae9.tar.gz
rm: fix memory leak on init failure
AVInputFormat.read_close is not called if AVInputFormat.read_header fails, so this needs to be handled separately. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavformat/rmdec.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index 299c74237c..d61e32764e 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -65,6 +65,8 @@ typedef struct {
int audio_pkt_cnt; ///< Output packet counter
} RMDemuxContext;
+static int rm_read_close(AVFormatContext *s);
+
static inline void get_strl(AVIOContext *pb, char *buf, int buf_size, int len)
{
int i;
@@ -505,6 +507,7 @@ static int rm_read_header(AVFormatContext *s)
unsigned int data_off = 0, indx_off = 0;
char buf[128], mime[128];
int flags = 0;
+ int ret = -1;
tag = avio_rl32(pb);
if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
@@ -519,7 +522,7 @@ static int rm_read_header(AVFormatContext *s)
for(;;) {
if (avio_feof(pb))
- return -1;
+ goto fail;
tag = avio_rl32(pb);
tag_size = avio_rb32(pb);
avio_rb16(pb);
@@ -531,7 +534,7 @@ static int rm_read_header(AVFormatContext *s)
tag,
tag_size);
if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
- return -1;
+ goto fail;
switch(tag) {
case MKTAG('P', 'R', 'O', 'P'):
/* file header */
@@ -553,8 +556,10 @@ static int rm_read_header(AVFormatContext *s)
break;
case MKTAG('M', 'D', 'P', 'R'):
st = avformat_new_stream(s, NULL);
- if (!st)
- return AVERROR(ENOMEM);
+ if (!st) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
st->id = avio_rb16(pb);
avio_rb32(pb); /* max bit rate */
st->codec->bit_rate = avio_rb32(pb); /* bit rate */
@@ -573,7 +578,7 @@ static int rm_read_header(AVFormatContext *s)
st->priv_data = ff_rm_alloc_rmstream();
if (ff_rm_read_mdpr_codecdata(s, s->pb, st, st->priv_data,
avio_rb32(pb), mime) < 0)
- return -1;
+ goto fail;
break;
case MKTAG('D', 'A', 'T', 'A'):
goto header_end;
@@ -598,6 +603,10 @@ static int rm_read_header(AVFormatContext *s)
}
return 0;
+
+fail:
+ rm_read_close(s);
+ return ret;
}
static int get_num(AVIOContext *pb, int *len)