Commit aab74a38 authored by wm4's avatar wm4 Committed by Michael Niedermayer

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: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 11d8fa5e
...@@ -65,6 +65,8 @@ typedef struct { ...@@ -65,6 +65,8 @@ typedef struct {
int audio_pkt_cnt; ///< Output packet counter int audio_pkt_cnt; ///< Output packet counter
} RMDemuxContext; } RMDemuxContext;
static int rm_read_close(AVFormatContext *s);
static inline void get_strl(AVIOContext *pb, char *buf, int buf_size, int len) static inline void get_strl(AVIOContext *pb, char *buf, int buf_size, int len)
{ {
int i; int i;
...@@ -505,6 +507,7 @@ static int rm_read_header(AVFormatContext *s) ...@@ -505,6 +507,7 @@ static int rm_read_header(AVFormatContext *s)
unsigned int data_off = 0, indx_off = 0; unsigned int data_off = 0, indx_off = 0;
char buf[128], mime[128]; char buf[128], mime[128];
int flags = 0; int flags = 0;
int ret = -1;
tag = avio_rl32(pb); tag = avio_rl32(pb);
if (tag == MKTAG('.', 'r', 'a', 0xfd)) { if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
...@@ -519,7 +522,7 @@ static int rm_read_header(AVFormatContext *s) ...@@ -519,7 +522,7 @@ static int rm_read_header(AVFormatContext *s)
for(;;) { for(;;) {
if (avio_feof(pb)) if (avio_feof(pb))
return -1; goto fail;
tag = avio_rl32(pb); tag = avio_rl32(pb);
tag_size = avio_rb32(pb); tag_size = avio_rb32(pb);
avio_rb16(pb); avio_rb16(pb);
...@@ -531,7 +534,7 @@ static int rm_read_header(AVFormatContext *s) ...@@ -531,7 +534,7 @@ static int rm_read_header(AVFormatContext *s)
tag, tag,
tag_size); tag_size);
if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A')) if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
return -1; goto fail;
switch(tag) { switch(tag) {
case MKTAG('P', 'R', 'O', 'P'): case MKTAG('P', 'R', 'O', 'P'):
/* file header */ /* file header */
...@@ -553,8 +556,10 @@ static int rm_read_header(AVFormatContext *s) ...@@ -553,8 +556,10 @@ static int rm_read_header(AVFormatContext *s)
break; break;
case MKTAG('M', 'D', 'P', 'R'): case MKTAG('M', 'D', 'P', 'R'):
st = avformat_new_stream(s, NULL); st = avformat_new_stream(s, NULL);
if (!st) if (!st) {
return AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto fail;
}
st->id = avio_rb16(pb); st->id = avio_rb16(pb);
avio_rb32(pb); /* max bit rate */ avio_rb32(pb); /* max bit rate */
st->codec->bit_rate = avio_rb32(pb); /* bit rate */ st->codec->bit_rate = avio_rb32(pb); /* bit rate */
...@@ -573,7 +578,7 @@ static int rm_read_header(AVFormatContext *s) ...@@ -573,7 +578,7 @@ static int rm_read_header(AVFormatContext *s)
st->priv_data = ff_rm_alloc_rmstream(); st->priv_data = ff_rm_alloc_rmstream();
if (ff_rm_read_mdpr_codecdata(s, s->pb, st, st->priv_data, if (ff_rm_read_mdpr_codecdata(s, s->pb, st, st->priv_data,
avio_rb32(pb), mime) < 0) avio_rb32(pb), mime) < 0)
return -1; goto fail;
break; break;
case MKTAG('D', 'A', 'T', 'A'): case MKTAG('D', 'A', 'T', 'A'):
goto header_end; goto header_end;
...@@ -598,6 +603,10 @@ static int rm_read_header(AVFormatContext *s) ...@@ -598,6 +603,10 @@ static int rm_read_header(AVFormatContext *s)
} }
return 0; return 0;
fail:
rm_read_close(s);
return ret;
} }
static int get_num(AVIOContext *pb, int *len) static int get_num(AVIOContext *pb, int *len)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment