[xiph-commits] r17530 - trunk/Tremor

tterribe at svn.xiph.org tterribe at svn.xiph.org
Wed Oct 13 18:33:46 PDT 2010


Author: tterribe
Date: 2010-10-13 18:33:46 -0700 (Wed, 13 Oct 2010)
New Revision: 17530

Modified:
   trunk/Tremor/codebook.c
   trunk/Tremor/codebook.h
   trunk/Tremor/info.c
   trunk/Tremor/sharedbook.c
Log:
Port r17029 and r17050 from libvorbis.

Fix leak when aborting out of static_codebook unpack.  Closes #1663.


Modified: trunk/Tremor/codebook.c
===================================================================
--- trunk/Tremor/codebook.c	2010-10-14 01:23:28 UTC (rev 17529)
+++ trunk/Tremor/codebook.c	2010-10-14 01:33:46 UTC (rev 17530)
@@ -25,9 +25,9 @@
 
 /* unpacks a codebook from the packet buffer into the codebook struct,
    readies the codebook auxiliary structures for decode *************/
-int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
+static_codebook *vorbis_staticbook_unpack(oggpack_buffer *opb){
   long i,j;
-  memset(s,0,sizeof(*s));
+  static_codebook *s=_ogg_calloc(1,sizeof(*s));
 
   /* make sure alignment is correct */
   if(oggpack_read(opb,24)!=0x564342)goto _eofout;
@@ -85,7 +85,7 @@
     break;
   default:
     /* EOF */
-    return(-1);
+    goto _eofout;
   }
   
   /* Do we have a mapping to unpack? */
@@ -127,12 +127,12 @@
   }
 
   /* all set */
-  return(0);
+  return(s);
   
  _errout:
  _eofout:
-  vorbis_staticbook_clear(s);
-  return(-1); 
+  vorbis_staticbook_destroy(s);
+  return(NULL); 
 }
 
 /* the 'eliminate the decode tree' optimization actually requires the

Modified: trunk/Tremor/codebook.h
===================================================================
--- trunk/Tremor/codebook.h	2010-10-14 01:23:28 UTC (rev 17529)
+++ trunk/Tremor/codebook.h	2010-10-14 01:33:46 UTC (rev 17530)
@@ -76,14 +76,13 @@
 
 } codebook;
 
-extern void vorbis_staticbook_clear(static_codebook *b);
 extern void vorbis_staticbook_destroy(static_codebook *b);
 extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
 
 extern void vorbis_book_clear(codebook *b);
 extern long _book_maptype1_quantvals(const static_codebook *b);
 
-extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
+extern static_codebook *vorbis_staticbook_unpack(oggpack_buffer *b);
 
 extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
 extern long vorbis_book_decodevs_add(codebook *book, ogg_int32_t *a, 

Modified: trunk/Tremor/info.c
===================================================================
--- trunk/Tremor/info.c	2010-10-14 01:23:28 UTC (rev 17529)
+++ trunk/Tremor/info.c	2010-10-14 01:33:46 UTC (rev 17530)
@@ -233,8 +233,8 @@
   ci->books=oggpack_read(opb,8)+1;
   if(ci->books<=0)goto err_out;
   for(i=0;i<ci->books;i++){
-    ci->book_param[i]=(static_codebook *)_ogg_calloc(1,sizeof(*ci->book_param[i]));
-    if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
+    ci->book_param[i]=vorbis_staticbook_unpack(opb);
+    if(!ci->book_param[i])goto err_out;
   }
 
   /* time backend settings */

Modified: trunk/Tremor/sharedbook.c
===================================================================
--- trunk/Tremor/sharedbook.c	2010-10-14 01:23:28 UTC (rev 17529)
+++ trunk/Tremor/sharedbook.c	2010-10-14 01:33:46 UTC (rev 17530)
@@ -294,15 +294,10 @@
   return(NULL);
 }
 
-void vorbis_staticbook_clear(static_codebook *b){
+void vorbis_staticbook_destroy(static_codebook *b){
   if(b->quantlist)_ogg_free(b->quantlist);
   if(b->lengthlist)_ogg_free(b->lengthlist);
   memset(b,0,sizeof(*b));
-
-}
-
-void vorbis_staticbook_destroy(static_codebook *b){
-  vorbis_staticbook_clear(b);
   _ogg_free(b);
 }
 



More information about the commits mailing list