diff options
author | Aurelien Jacobs <aurel@gnuage.org> | 2009-01-06 22:11:04 +0000 |
---|---|---|
committer | Aurelien Jacobs <aurel@gnuage.org> | 2009-01-06 22:11:04 +0000 |
commit | 094d9df72e8372b0a7c6e9381b375b438db3fa3c (patch) | |
tree | bc1ecfa16f0b5b5dd14c9a9910f343d4a11b22e5 | |
parent | 16cda1535edf853c31506b2c737d0a6873744550 (diff) | |
download | ffmpeg-094d9df72e8372b0a7c6e9381b375b438db3fa3c.tar.gz |
free all allocated metadata structures
Originally committed as revision 16457 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | ffmpeg.c | 8 | ||||
-rw-r--r-- | libavformat/avformat.h | 5 | ||||
-rw-r--r-- | libavformat/metadata.c | 14 | ||||
-rw-r--r-- | libavformat/utils.c | 12 |
4 files changed, 31 insertions, 8 deletions
@@ -396,9 +396,17 @@ static int av_exit(int ret) if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) url_fclose(s->pb); for(j=0;j<s->nb_streams;j++) { + av_metadata_free(&s->streams[j]->metadata); av_free(s->streams[j]->codec); av_free(s->streams[j]); } + for(j=0;j<s->nb_programs;j++) { + av_metadata_free(&s->programs[j]->metadata); + } + for(j=0;j<s->nb_chapters;j++) { + av_metadata_free(&s->chapters[j]->metadata); + } + av_metadata_free(&s->metadata); av_free(s); } for(i=0;i<nb_input_files;i++) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index e21b3ea182..e8b71004e7 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -93,6 +93,11 @@ av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int f */ int av_metadata_set(AVMetadata **m, AVMetadataTag tag); +/** + * Free all the memory allocated for an AVMetadata struct. + */ +void av_metadata_free(AVMetadata **m); + /* packet functions */ diff --git a/libavformat/metadata.c b/libavformat/metadata.c index 5c7ef06199..70bfa3d35b 100644 --- a/libavformat/metadata.c +++ b/libavformat/metadata.c @@ -74,6 +74,20 @@ int av_metadata_set(AVMetadata **pm, AVMetadataTag elem) return 0; } +void av_metadata_free(AVMetadata **pm) +{ + AVMetadata *m= *pm; + + if(m){ + while(m->count--){ + av_free(m->elems[m->count].key); + av_free(m->elems[m->count].value); + } + av_free(m->elems); + } + av_freep(pm); +} + #if LIBAVFORMAT_VERSION_MAJOR < 53 #define FILL_METADATA(s, key, value) { \ if (value && *value && \ diff --git a/libavformat/utils.c b/libavformat/utils.c index e3fdd7f744..eb5549979f 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2285,6 +2285,7 @@ void av_close_input_stream(AVFormatContext *s) if (st->parser) { av_parser_close(st->parser); } + av_metadata_free(&st->metadata); av_free(st->index_entries); av_free(st->codec->extradata); av_free(st->codec); @@ -2295,6 +2296,7 @@ void av_close_input_stream(AVFormatContext *s) for(i=s->nb_programs-1; i>=0; i--) { av_freep(&s->programs[i]->provider_name); av_freep(&s->programs[i]->name); + av_metadata_free(&s->programs[i]->metadata); av_freep(&s->programs[i]->stream_index); av_freep(&s->programs[i]); } @@ -2303,17 +2305,11 @@ void av_close_input_stream(AVFormatContext *s) av_freep(&s->priv_data); while(s->nb_chapters--) { av_free(s->chapters[s->nb_chapters]->title); + av_metadata_free(&s->chapters[s->nb_chapters]->metadata); av_free(s->chapters[s->nb_chapters]); } av_freep(&s->chapters); - if(s->metadata){ - while(s->metadata->count--){ - av_freep(&s->metadata->elems[s->metadata->count].key); - av_freep(&s->metadata->elems[s->metadata->count].value); - } - av_freep(&s->metadata->elems); - } - av_freep(&s->metadata); + av_metadata_free(&s->metadata); av_free(s); } |