changeset 4161:6a7275621c02 libavformat

free all allocated metadata structures
author aurel
date Tue, 06 Jan 2009 22:11:04 +0000
parents e7c4a867349a
children d9dede8fe890
files avformat.h metadata.c utils.c
diffstat 3 files changed, 23 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/avformat.h	Tue Jan 06 17:50:10 2009 +0000
+++ b/avformat.h	Tue Jan 06 22:11:04 2009 +0000
@@ -93,6 +93,11 @@
  */
 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 */
 
--- a/metadata.c	Tue Jan 06 17:50:10 2009 +0000
+++ b/metadata.c	Tue Jan 06 22:11:04 2009 +0000
@@ -74,6 +74,20 @@
     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 &&                                                    \
--- a/utils.c	Tue Jan 06 17:50:10 2009 +0000
+++ b/utils.c	Tue Jan 06 22:11:04 2009 +0000
@@ -2285,6 +2285,7 @@
         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 @@
     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 @@
     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);
 }