From 4b83fc0fe414dc7959a5511fcdce320ad90ac7ba Mon Sep 17 00:00:00 2001 From: Vitor Sessak Date: Wed, 3 Mar 2010 17:31:24 +0000 Subject: [PATCH] Plug memory leak in NUT muxer and demuxer Originally committed as revision 22174 to svn://svn.ffmpeg.org/ffmpeg/trunk --- doc/APIchanges | 3 +++ libavformat/nut.c | 11 +++++++++++ libavformat/nut.h | 1 + libavformat/nutdec.c | 1 + libavformat/nutenc.c | 1 + libavutil/avutil.h | 2 +- libavutil/tree.c | 2 -- libavutil/tree.h | 13 +++++++++++++ 8 files changed, 31 insertions(+), 3 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 957096ab29..e001265b63 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -12,6 +12,9 @@ libavutil: 2009-03-08 API changes, most recent first: +2010-03-03 - r22174 - lavu 50.10.0 - av_tree_enumerate() + Add av_tree_enumerate(). + 2010-02-07 - r21673 - lavu 50.9.0 - av_compare_ts() Add av_compare_ts(). diff --git a/libavformat/nut.c b/libavformat/nut.c index be6bcf6a42..d969bbc526 100644 --- a/libavformat/nut.c +++ b/libavformat/nut.c @@ -69,6 +69,17 @@ void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts){ } } +static void enu_free(void *opaque, void *elem) +{ + av_free(elem); +} + +void ff_nut_free_sp(NUTContext *nut) +{ + av_tree_enumerate(nut->syncpoints, NULL, NULL, enu_free); + av_tree_destroy(nut->syncpoints); +} + const Dispositions ff_nut_dispositions[] = { {"default" , AV_DISPOSITION_DEFAULT}, {"dub" , AV_DISPOSITION_DUB}, diff --git a/libavformat/nut.h b/libavformat/nut.h index 35593e97b7..8d9695245c 100644 --- a/libavformat/nut.h +++ b/libavformat/nut.h @@ -110,6 +110,7 @@ int64_t ff_lsb2full(StreamContext *stream, int64_t lsb); int ff_nut_sp_pos_cmp(Syncpoint *a, Syncpoint *b); int ff_nut_sp_pts_cmp(Syncpoint *a, Syncpoint *b); void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts); +void ff_nut_free_sp(NUTContext *nut); extern const Dispositions ff_nut_dispositions[]; diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c index 171315b711..6a2d2f8cda 100644 --- a/libavformat/nutdec.c +++ b/libavformat/nutdec.c @@ -901,6 +901,7 @@ static int nut_read_close(AVFormatContext *s) av_freep(&nut->time_base); av_freep(&nut->stream); + ff_nut_free_sp(nut); for(i = 1; i < nut->header_count; i++) av_freep(&nut->header[i]); diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index 0cce48dea0..e06a85f54f 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -797,6 +797,7 @@ static int write_trailer(AVFormatContext *s){ while(nut->header_count<3) write_headers(nut, bc); put_flush_packet(bc); + ff_nut_free_sp(nut); av_freep(&nut->stream); av_freep(&nut->time_base); diff --git a/libavutil/avutil.h b/libavutil/avutil.h index b56f0ed4c2..b026046b36 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -40,7 +40,7 @@ #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c) #define LIBAVUTIL_VERSION_MAJOR 50 -#define LIBAVUTIL_VERSION_MINOR 9 +#define LIBAVUTIL_VERSION_MINOR 10 #define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ diff --git a/libavutil/tree.c b/libavutil/tree.c index 4b78764628..c387c46deb 100644 --- a/libavutil/tree.c +++ b/libavutil/tree.c @@ -135,7 +135,6 @@ void av_tree_destroy(AVTreeNode *t){ } } -#if 0 void av_tree_enumerate(AVTreeNode *t, void *opaque, int (*cmp)(void *opaque, void *elem), int (*enu)(void *opaque, void *elem)){ if(t){ 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 if(v<=0) av_tree_enumerate(t->child[1], opaque, cmp, enu); } } -#endif #ifdef TEST diff --git a/libavutil/tree.h b/libavutil/tree.h index e96d1fa12e..75191f4f7e 100644 --- a/libavutil/tree.h +++ b/libavutil/tree.h @@ -79,4 +79,17 @@ void *av_tree_find(const struct AVTreeNode *root, void *key, int (*cmp)(void *ke void *av_tree_insert(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b), struct AVTreeNode **next); void av_tree_destroy(struct AVTreeNode *t); +/** + * Applies enu(opaque, &elem) to all the elements in the tree in a given range. + * + * @param cmp a comparison function that returns < 0 for a element below the + * range, > 0 for a element above the range and == 0 for a + * element inside the range + * + * @note The cmp function should use the same ordering used to construct the + * tree. + */ +void av_tree_enumerate(struct AVTreeNode *t, void *opaque, int (*cmp)(void *opaque, void *elem), int (*enu)(void *opaque, void *elem)); + + #endif /* AVUTIL_TREE_H */