From fee6faa2b67fca0cf0889165cfa64b02fc8d395b Mon Sep 17 00:00:00 2001 From: Vitor Sessak Date: Sun, 28 Feb 2010 20:48:42 +0000 Subject: [PATCH] Implement av_tree_destroy_free_elem() to destroy a tree and free all the values stored on it. Originally committed as revision 22119 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavutil/tree.c | 9 +++++++++ libavutil/tree.h | 1 + 2 files changed, 10 insertions(+) diff --git a/libavutil/tree.c b/libavutil/tree.c index 4b78764628..261e306b8a 100644 --- a/libavutil/tree.c +++ b/libavutil/tree.c @@ -135,6 +135,15 @@ void av_tree_destroy(AVTreeNode *t){ } } +void av_tree_destroy_free_elem(AVTreeNode *t){ + if(t){ + av_tree_destroy_free_elem(t->child[0]); + av_tree_destroy_free_elem(t->child[1]); + av_free(t->elem); + av_free(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){ diff --git a/libavutil/tree.h b/libavutil/tree.h index e96d1fa12e..e3441c3392 100644 --- a/libavutil/tree.h +++ b/libavutil/tree.h @@ -78,5 +78,6 @@ 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); +void av_tree_destroy_free_elem(struct AVTreeNode *t); #endif /* AVUTIL_TREE_H */