mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-08 13:22:53 +02:00
avformat/mxfdec: Fix memleak when parsing tag fails
The MXF demuxer uses an array of pointers to different structures of
metadata (all containing a common initial sequence containing a type
field to distinguish them) and some of these structures contain pointers
to separately allocated subelements. If an error happens while reading
and creating the tags, the semi-finished new tag is freed using the
function to free these tags. But this function doesn't free the already
allocated subelements, because the type has not been set yet. This commit
changes this.
Reviewed-by: Tomas Härdin <tjoppen@acc.umu.se>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
(cherry picked from commit 78f21cab18
)
This commit is contained in:
parent
8e7eedf294
commit
6918d1281c
@ -2713,6 +2713,7 @@ static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = {
|
||||
|
||||
static int mxf_metadataset_init(MXFMetadataSet *ctx, enum MXFMetadataSetType type)
|
||||
{
|
||||
ctx->type = type;
|
||||
switch (type){
|
||||
case MultipleDescriptor:
|
||||
case Descriptor:
|
||||
@ -2733,7 +2734,8 @@ static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadF
|
||||
|
||||
if (!ctx)
|
||||
return AVERROR(ENOMEM);
|
||||
mxf_metadataset_init(ctx, type);
|
||||
if (ctx_size)
|
||||
mxf_metadataset_init(ctx, type);
|
||||
while (avio_tell(pb) + 4 < klv_end && !avio_feof(pb)) {
|
||||
int ret;
|
||||
int tag = avio_rb16(pb);
|
||||
@ -2772,7 +2774,6 @@ static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadF
|
||||
* it extending past the end of the KLV though (zzuf5.mxf). */
|
||||
if (avio_tell(pb) > klv_end) {
|
||||
if (ctx_size) {
|
||||
ctx->type = type;
|
||||
mxf_free_metadataset(&ctx, 1);
|
||||
}
|
||||
|
||||
@ -2783,7 +2784,6 @@ static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadF
|
||||
} else if (avio_tell(pb) <= next) /* only seek forward, else this can loop for a long time */
|
||||
avio_seek(pb, next, SEEK_SET);
|
||||
}
|
||||
if (ctx_size) ctx->type = type;
|
||||
return ctx_size ? mxf_add_metadata_set(mxf, &ctx) : 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user