[tremor] Memory leak in Tremor

lemieux berthier berthier_lemieux at hotmail.com
Wed Jul 30 04:23:49 PDT 2003


<div style='background-color:'><DIV>
<DIV>
<DIV>Hi,</DIV>
<DIV> </DIV>
<DIV>  I *think* I have sumbled across 2 memory leaks in file "framing.c". I am not very aware of internals of the decoder, so the solutions I present here might not be the best ones.</DIV>
<DIV> </DIV>
<DIV> First one, the most serious, the ogg_buffers are never destroyed. This seems to happen at least when executing the iVorbisfileExample. </DIV>
<DIV> </DIV>
<DIV> The problematic function seems to be _ogg_buffer_destroy:</DIV>
<DIV>There is a check if there are some outstanding buffer,  if(!bs->outstanding). If yes, the function just return. I think the function should really destroy these buffer, when bs->shutdown is 1. Otherwise, the buffer will never be destroyed.</DIV>
<DIV> </DIV>
<DIV>Here is a sketch of a solution, works fine on the .ogg files I've tested:</DIV>
<DIV> </DIV>
<DIV> static void _ogg_buffer_destroy(ogg_buffer_state *bs){  ogg_buffer *bt;<BR>  ogg_reference *rt;</DIV>
<DIV>  if(bs->shutdown){</DIV>
<DIV>    bt=bs->unused_buffers;    rt=bs->unused_references;</DIV>
<DIV>    while(bt){      ogg_buffer *b=bt;<BR>      bt=b->ptr.next;<BR>      if(b->data)_ogg_free(b->data);<BR>      _ogg_free(b);<BR>    }<BR>    bs->unused_buffers=0;<BR>    while(rt){<BR>      ogg_reference *r=rt;<BR>      rt=r->next;<BR>      _ogg_free(r);<BR>    }<BR>    bs->unused_references=0;<BR> if(!bs->outstanding){<BR>      _ogg_free(bs);<BR>    }<BR>    else<BR>        {<BR>        /* This should never happen ?*/<BR>        exit(-1);<BR>        }<BR>  }<BR>}</DIV>
<DIV> </DIV>
<DIV>Other leak is that the oggstreams are never deleted, they are simply set to 0. Simply freeing them seems to work ok. Here is what I did:</DIV>
<DIV> </DIV>
<DIV>int ogg_stream_destroy(ogg_stream_state *os){  if(os){<BR>    ogg_buffer_release(os->header_tail);<BR>    ogg_buffer_release(os->body_tail);<BR>    _ogg_free(os);<BR>  }<BR>  return OGG_SUCCESS;<BR>} </DIV>
<DIV> </DIV>
<DIV>I hope this is might be useful for somebody...</DIV>
<DIV> </DIV>
<DIV>-Berthier</DIV></DIV></DIV></div><br clear=all><hr>Add photos to your e-mail with MSN 8. Get 2 months FREE*.
--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'tremor-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Tremor mailing list