[FFmpeg-devel] Question: infinite loop in av_tree_destroy(..)

Aurelien Jacobs aurel
Sat Jan 3 19:43:43 CET 2009


Stefano Sabatini wrote:

> On date Saturday 2009-01-03 23:37:55 +0800, avcoder encoded:
> > Dear:
> > //@file:libavutil/tree.c
> > void av_tree_destroy(AVTreeNode *t){
> >     av_tree_destroy(t->child[0]);
> >     av_tree_destroy(t->child[1]);
> >     av_free(t);
> > }
> > 
> > It seems that the codes is wrong!
> 
> Looks OK to me. Why do you think is wrong?

Because it lacks an ending condition...
Something like this may be better:

Index: libavutil/tree.c
===================================================================
--- libavutil/tree.c	(revision 16263)
+++ libavutil/tree.c	(working copy)
@@ -128,9 +128,11 @@
 }
 
 void av_tree_destroy(AVTreeNode *t){
+    if(t){
     av_tree_destroy(t->child[0]);
     av_tree_destroy(t->child[1]);
     av_free(t);
+    }
 }
 
 #if 0

Aurel




More information about the ffmpeg-devel mailing list