avformat/mxfdec: Fix cleanup in mxf_free_metadataset()

Fixes Ticket4256

Found-by: tholin
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
pull/115/head
Carl Eugen Hoyos 10 years ago committed by Michael Niedermayer
parent 840570d27b
commit 449b8cf04b
  1. 11
      libavformat/mxfdec.c

@ -284,7 +284,7 @@ static const uint8_t mxf_avid_project_name[] = { 0xa5,0xfb,0x7b,0x
#define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y))) #define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y)))
static void mxf_free_metadataset(MXFMetadataSet **ctx) static void mxf_free_metadataset(MXFMetadataSet **ctx, int freectx)
{ {
MXFIndexTableSegment *seg; MXFIndexTableSegment *seg;
switch ((*ctx)->type) { switch ((*ctx)->type) {
@ -313,6 +313,7 @@ static void mxf_free_metadataset(MXFMetadataSet **ctx)
default: default:
break; break;
} }
if (freectx)
av_freep(ctx); av_freep(ctx);
} }
@ -2213,7 +2214,7 @@ static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadF
if (ctx_size && tag == 0x3C0A) { if (ctx_size && tag == 0x3C0A) {
avio_read(pb, ctx->uid, 16); avio_read(pb, ctx->uid, 16);
} else if ((ret = read_child(ctx, pb, tag, size, uid, -1)) < 0) { } else if ((ret = read_child(ctx, pb, tag, size, uid, -1)) < 0) {
mxf_free_metadataset(&ctx); mxf_free_metadataset(&ctx, !!ctx_size);
return ret; return ret;
} }
@ -2222,7 +2223,7 @@ static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadF
if (avio_tell(pb) > klv_end) { if (avio_tell(pb) > klv_end) {
if (ctx_size) { if (ctx_size) {
ctx->type = type; ctx->type = type;
mxf_free_metadataset(&ctx); mxf_free_metadataset(&ctx, !!ctx_size);
} }
av_log(mxf->fc, AV_LOG_ERROR, av_log(mxf->fc, AV_LOG_ERROR,
@ -2504,7 +2505,7 @@ static int mxf_handle_missing_index_segment(MXFContext *mxf)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if ((ret = mxf_add_metadata_set(mxf, segment))) { if ((ret = mxf_add_metadata_set(mxf, segment))) {
mxf_free_metadataset((MXFMetadataSet**)&segment); mxf_free_metadataset((MXFMetadataSet**)&segment, 1);
return ret; return ret;
} }
@ -2977,7 +2978,7 @@ static int mxf_read_close(AVFormatContext *s)
s->streams[i]->priv_data = NULL; s->streams[i]->priv_data = NULL;
for (i = 0; i < mxf->metadata_sets_count; i++) { for (i = 0; i < mxf->metadata_sets_count; i++) {
mxf_free_metadataset(mxf->metadata_sets + i); mxf_free_metadataset(mxf->metadata_sets + i, 1);
} }
av_freep(&mxf->partitions); av_freep(&mxf->partitions);
av_freep(&mxf->metadata_sets); av_freep(&mxf->metadata_sets);

Loading…
Cancel
Save