[xiph-cvs] cvs commit: ogg/src stream.c sync.c

Monty xiphmont at xiph.org
Fri Mar 28 16:07:33 PST 2003



xiphmont    03/03/28 19:07:33

  Modified:    src      Tag: libogg2-zerocopy stream.c sync.c
  Log:
  Additional API-related memory management behavior clarified and tweaked.
  
  Monty

Revision  Changes    Path
No                   revision

<p>No                   revision

<p>1.1.2.12  +34 -28    ogg/src/Attic/stream.c

Index: stream.c
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/stream.c,v
retrieving revision 1.1.2.11
retrieving revision 1.1.2.12
diff -u -r1.1.2.11 -r1.1.2.12
--- stream.c	28 Mar 2003 22:37:16 -0000	1.1.2.11
+++ stream.c	29 Mar 2003 00:07:32 -0000	1.1.2.12
@@ -12,7 +12,7 @@
 
  function: code raw packets into framed Ogg logical stream and
            decode Ogg logical streams back into raw packets
- last mod: $Id: stream.c,v 1.1.2.11 2003/03/28 22:37:16 xiphmont Exp $
+ last mod: $Id: stream.c,v 1.1.2.12 2003/03/29 00:07:32 xiphmont Exp $
 
  ********************************************************************/
 
@@ -172,11 +172,12 @@
   long body_bytes=0;
   int i;
 
+  /* if the incoming page is still valid (and thus unconsumed),
+     release it to prevent a leak */
+  ogg_page_release(og);
+
   /* is there a page waiting to come back? */
-  if(!os->header_tail){
-    if(og)memset(og,0,sizeof(*og));
-    return 0;
-  }
+  if(!os->header_tail) return 0;
 
   /* get header and body sizes */
   oggbyte_init(&ob,os->header_tail,0);
@@ -426,6 +427,11 @@
 
 static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
 
+  /* if the incoming packet is a valid reference, release it such that
+     we don't leak the memory */
+  ogg_packet_release(op);
+
+  /* buffer packets for return */
   _span_queued_page(os);
 
   if(os->holeflag){
@@ -436,7 +442,6 @@
       os->holeflag=1;
     if(temp==2){
       os->packetno++;
-      if(op)memset(op,0,sizeof(*op));
       return OGG_HOLE;
     }
   }
@@ -448,15 +453,11 @@
       os->spanflag=1;
     if(temp==2){
       os->packetno++;
-      if(op)memset(op,0,sizeof(*op));
       return OGG_SPAN;
     }
   }
 
-  if(!(os->body_fill&FINFLAG)){
-    if(op)memset(op,0,sizeof(*op));
-    return 0;
-  }
+  if(!(os->body_fill&FINFLAG)) return 0;
   if(!op && !adv)return 1; /* just using peek as an inexpensive way
                                to ask if there's a whole packet
                                waiting */
@@ -513,15 +514,19 @@
 }
 
 int ogg_packet_release(ogg_packet *op) {
-  ogg_buffer_release(op->packet);
-  memset(op, 0, sizeof(*op));
+  if(op){
+    ogg_buffer_release(op->packet);
+    memset(op, 0, sizeof(*op));
+  }
   return OGG_SUCCESS;
 }
 
 int ogg_page_release(ogg_page *og) {
-  ogg_buffer_release(og->header);
-  ogg_buffer_release(og->body);
-  memset(og, 0, sizeof(*og));
+  if(og){
+    ogg_buffer_release(og->header);
+    ogg_buffer_release(og->body);
+    memset(og, 0, sizeof(*og));
+  }
   return OGG_SUCCESS;
 }
 
@@ -881,7 +886,7 @@
 
   for(i=0;i<packets;i++){
     /* construct a test packet */
-    ogg_packet op;
+    ogg_packet op={0,0,0,0,0,0};
     int len=pl[i];
     
     op.packet=ogg_buffer_alloc(bs,len);
@@ -900,7 +905,7 @@
 
     /* retrieve any finished pages */
     {
-      ogg_page og;
+      ogg_page og={0,0,0,0};
       
       while(ogg_stream_pageout(os_en,&og)){
         /* We have a page.  Check it carefully */
@@ -920,8 +925,8 @@
         /* have a complete page; submit it to sync/decode */
 
         {
-	  ogg_page og_de;
-	  ogg_packet op_de,op_de2;
+	  ogg_page og_de={0,0,0,0};
+	  ogg_packet op_de={0,0,0,0,0,0},op_de2={0,0,0,0,0,0};
           int blen=ogg_buffer_length(og.header)+ogg_buffer_length(og.body);
           char *buf=ogg_sync_bufferin(oy,blen);
           bufcpy(buf,og.header);
@@ -1159,6 +1164,7 @@
     int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
     int inptr=0,i,j;
     ogg_page og[5];
+    memset(og,0,sizeof(og));
     
     ogg_stream_reset(os_en);
 
@@ -1197,8 +1203,8 @@
     
     /* Test lost pages on pagein/packetout: no rollback */
     {
-      ogg_page temp;
-      ogg_packet test;
+      ogg_page temp={0,0,0,0};
+      ogg_packet test={0,0,0,0,0,0};
 
       fprintf(stderr,"Testing loss of pages... ");
 
@@ -1249,8 +1255,8 @@
 
     /* Test lost pages on pagein/packetout: rollback with continuation */
     {
-      ogg_page temp;
-      ogg_packet test;
+      ogg_page temp={0,0,0,0};
+      ogg_packet test={0,0,0,0,0,0};
 
       fprintf(stderr,"Testing loss of pages (rollback required)... ");
 
@@ -1303,7 +1309,7 @@
     
     /* the rest only test sync */
     {
-      ogg_page og_de;
+      ogg_page og_de={0,0,0,0};
       /* Test fractional page inputs: incomplete capture */
       fprintf(stderr,"Testing sync on partial inputs... ");
       ogg_sync_reset(oy);
@@ -1346,7 +1352,7 @@
 
     /* Test fractional page inputs: page + incomplete capture */
     {
-      ogg_page og_de;
+      ogg_page og_de={0,0,0,0};
       fprintf(stderr,"Testing sync on 1+partial inputs... ");
       ogg_sync_reset(oy); 
 
@@ -1377,7 +1383,7 @@
     
     /* Test recapture: garbage + page */
     {
-      ogg_page og_de;
+      ogg_page og_de={0,0,0,0};
       fprintf(stderr,"Testing search for capture... ");
       ogg_sync_reset(oy); 
       
@@ -1414,7 +1420,7 @@
 
     /* Test recapture: page + garbage + page */
     {
-      ogg_page og_de;
+      ogg_page og_de={0,0,0,0};
       fprintf(stderr,"Testing recapture... ");
       ogg_sync_reset(oy); 
 

<p><p>1.1.2.12  +4 -2      ogg/src/Attic/sync.c

Index: sync.c
===================================================================
RCS file: /usr/local/cvsroot/ogg/src/Attic/sync.c,v
retrieving revision 1.1.2.11
retrieving revision 1.1.2.12
diff -u -r1.1.2.11 -r1.1.2.12
--- sync.c	28 Mar 2003 22:37:16 -0000	1.1.2.11
+++ sync.c	29 Mar 2003 00:07:32 -0000	1.1.2.12
@@ -12,7 +12,7 @@
 
  function: decode stream sync and memory management foundation code;
            takes in raw data, spits out packets
- last mod: $Id: sync.c,v 1.1.2.11 2003/03/28 22:37:16 xiphmont Exp $
+ last mod: $Id: sync.c,v 1.1.2.12 2003/03/29 00:07:32 xiphmont Exp $
 
  note: The CRC code is directly derived from public domain code by
  Ross Williams (ross at guest.adelaide.edu.au).  See docs/framing.html
@@ -284,6 +284,9 @@
   oggbyte_buffer page;
   long           bytes,ret=0;
 
+  /* don't leak a valid reference */
+  ogg_page_release(og);
+
   bytes=oy->fifo_fill;
   oggbyte_init(&page,oy->fifo_tail,0);
 
@@ -380,7 +383,6 @@
   oy->fifo_fill+=ret;
 
  sync_out:
-  if(og)memset(og,0,sizeof(*og));
   return ret;
 }
 

<p><p>--- >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 'cvs-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 commits mailing list