Browse code

Plug memory leak in NUT muxer and demuxer

Originally committed as revision 22174 to svn://svn.ffmpeg.org/ffmpeg/trunk

Vitor Sessak authored on 2010/03/04 02:31:24
Showing 8 changed files
... ...
@@ -12,6 +12,9 @@ libavutil:   2009-03-08
12 12
 
13 13
 API changes, most recent first:
14 14
 
15
+2010-03-03 - r22174 - lavu 50.10.0 - av_tree_enumerate()
16
+  Add av_tree_enumerate().
17
+
15 18
 2010-02-07 - r21673 - lavu 50.9.0 - av_compare_ts()
16 19
   Add av_compare_ts().
17 20
 
... ...
@@ -69,6 +69,17 @@ void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts){
69 69
     }
70 70
 }
71 71
 
72
+static void enu_free(void *opaque, void *elem)
73
+{
74
+    av_free(elem);
75
+}
76
+
77
+void ff_nut_free_sp(NUTContext *nut)
78
+{
79
+    av_tree_enumerate(nut->syncpoints, NULL, NULL, enu_free);
80
+    av_tree_destroy(nut->syncpoints);
81
+}
82
+
72 83
 const Dispositions ff_nut_dispositions[] = {
73 84
     {"default"     , AV_DISPOSITION_DEFAULT},
74 85
     {"dub"         , AV_DISPOSITION_DUB},
... ...
@@ -110,6 +110,7 @@ int64_t ff_lsb2full(StreamContext *stream, int64_t lsb);
110 110
 int ff_nut_sp_pos_cmp(Syncpoint *a, Syncpoint *b);
111 111
 int ff_nut_sp_pts_cmp(Syncpoint *a, Syncpoint *b);
112 112
 void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts);
113
+void ff_nut_free_sp(NUTContext *nut);
113 114
 
114 115
 extern const Dispositions ff_nut_dispositions[];
115 116
 
... ...
@@ -901,6 +901,7 @@ static int nut_read_close(AVFormatContext *s)
901 901
 
902 902
     av_freep(&nut->time_base);
903 903
     av_freep(&nut->stream);
904
+    ff_nut_free_sp(nut);
904 905
     for(i = 1; i < nut->header_count; i++)
905 906
         av_freep(&nut->header[i]);
906 907
 
... ...
@@ -797,6 +797,7 @@ static int write_trailer(AVFormatContext *s){
797 797
     while(nut->header_count<3)
798 798
         write_headers(nut, bc);
799 799
     put_flush_packet(bc);
800
+    ff_nut_free_sp(nut);
800 801
     av_freep(&nut->stream);
801 802
     av_freep(&nut->time_base);
802 803
 
... ...
@@ -40,7 +40,7 @@
40 40
 #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
41 41
 
42 42
 #define LIBAVUTIL_VERSION_MAJOR 50
43
-#define LIBAVUTIL_VERSION_MINOR  9
43
+#define LIBAVUTIL_VERSION_MINOR 10
44 44
 #define LIBAVUTIL_VERSION_MICRO  0
45 45
 
46 46
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
... ...
@@ -135,7 +135,6 @@ void av_tree_destroy(AVTreeNode *t){
135 135
     }
136 136
 }
137 137
 
138
-#if 0
139 138
 void av_tree_enumerate(AVTreeNode *t, void *opaque, int (*cmp)(void *opaque, void *elem), int (*enu)(void *opaque, void *elem)){
140 139
     if(t){
141 140
         int v= cmp ? cmp(opaque, t->elem) : 0;
... ...
@@ -144,7 +143,6 @@ void av_tree_enumerate(AVTreeNode *t, void *opaque, int (*cmp)(void *opaque, voi
144 144
         if(v<=0) av_tree_enumerate(t->child[1], opaque, cmp, enu);
145 145
     }
146 146
 }
147
-#endif
148 147
 
149 148
 #ifdef TEST
150 149
 
... ...
@@ -79,4 +79,17 @@ void *av_tree_find(const struct AVTreeNode *root, void *key, int (*cmp)(void *ke
79 79
 void *av_tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b), struct AVTreeNode **next);
80 80
 void av_tree_destroy(struct AVTreeNode *t);
81 81
 
82
+/**
83
+ * Applies enu(opaque, &elem) to all the elements in the tree in a given range.
84
+ *
85
+ * @param cmp a comparison function that returns < 0 for a element below the
86
+ *            range, > 0 for a element above the range and == 0 for a
87
+ *            element inside the range
88
+ *
89
+ * @note The cmp function should use the same ordering used to construct the
90
+ *       tree.
91
+ */
92
+void av_tree_enumerate(struct AVTreeNode *t, void *opaque, int (*cmp)(void *opaque, void *elem), int (*enu)(void *opaque, void *elem));
93
+
94
+
82 95
 #endif /* AVUTIL_TREE_H */