[xiph-commits] r15613 - icecast/trunk/icecast/src

karl at svn.xiph.org karl at svn.xiph.org
Wed Jan 7 19:35:54 PST 2009


Author: karl
Date: 2009-01-07 19:35:54 -0800 (Wed, 07 Jan 2009)
New Revision: 15613

Modified:
   icecast/trunk/icecast/src/format_ogg.c
   icecast/trunk/icecast/src/refbuf.c
   icecast/trunk/icecast/src/source.c
Log:
Don't free up the second, third... header pages, as those are only referenced
once, only the first page is refcounted multiple times by the queue. Put some
checks in to help capture odd cases if they arise.


Modified: icecast/trunk/icecast/src/format_ogg.c
===================================================================
--- icecast/trunk/icecast/src/format_ogg.c	2009-01-08 03:20:10 UTC (rev 15612)
+++ icecast/trunk/icecast/src/format_ogg.c	2009-01-08 03:35:54 UTC (rev 15613)
@@ -120,6 +120,7 @@
     {
         refbuf_t *to_release = header;
         header = header->next;
+        to_release->next = NULL;
         refbuf_release (to_release);
     }
     ogg_info->header_pages = NULL;

Modified: icecast/trunk/icecast/src/refbuf.c
===================================================================
--- icecast/trunk/icecast/src/refbuf.c	2009-01-08 03:20:10 UTC (rev 15612)
+++ icecast/trunk/icecast/src/refbuf.c	2009-01-08 03:35:54 UTC (rev 15613)
@@ -25,6 +25,11 @@
 
 #include "refbuf.h"
 
+#define CATMODULE "refbuf"
+
+#include "logging.h"
+
+
 void refbuf_initialize(void)
 {
 }
@@ -33,22 +38,19 @@
 {
 }
 
-refbuf_t *refbuf_new(unsigned int size)
+refbuf_t *refbuf_new (unsigned int size)
 {
     refbuf_t *refbuf;
 
     refbuf = (refbuf_t *)malloc(sizeof(refbuf_t));
     if (refbuf == NULL)
-        return NULL;
+        abort();
     refbuf->data = NULL;
     if (size)
     {
         refbuf->data = malloc (size);
         if (refbuf->data == NULL)
-        {
-            free (refbuf);
-            return NULL;
-        }
+            abort();
     }
     refbuf->len = size;
     refbuf->sync_point = 0;
@@ -64,18 +66,29 @@
     self->_count++;
 }
 
+static void refbuf_release_associated (refbuf_t *ref)
+{
+    if (ref == NULL)
+        return;
+    while (ref && ref->_count == 1)
+    {
+        refbuf_t *to_go = ref;
+        ref = to_go->next;
+        to_go->next = NULL;
+        refbuf_release (to_go);
+    }
+}
+
 void refbuf_release(refbuf_t *self)
 {
     if (self == NULL)
         return;
     self->_count--;
-    if (self->_count == 0) {
-        while (self->associated)
-        {
-            refbuf_t *ref = self->associated;
-            self->associated = ref->next;
-            refbuf_release (ref);
-        }
+    if (self->_count == 0)
+    {
+        refbuf_release_associated (self->associated);
+        if (self->next)
+            DEBUG0 ("next not null");
         free(self->data);
         free(self);
     }

Modified: icecast/trunk/icecast/src/source.c
===================================================================
--- icecast/trunk/icecast/src/source.c	2009-01-08 03:20:10 UTC (rev 15612)
+++ icecast/trunk/icecast/src/source.c	2009-01-08 03:35:54 UTC (rev 15613)
@@ -239,6 +239,7 @@
     {
         refbuf_t *p = source->stream_data;
         source->stream_data = p->next;
+        p->next = NULL;
         /* can be referenced by burst handler as well */
         while (p->_count > 1)
             refbuf_release (p);
@@ -806,6 +807,7 @@
                 }
                 source->stream_data = to_go->next;
                 source->queue_size -= to_go->len;
+                to_go->next = NULL;
                 refbuf_release (to_go);
             }
         }



More information about the commits mailing list