# HG changeset patch # User Matti Hamalainen # Date 1307647780 -10800 # Node ID 18e292701db46a3805104578ca1b44579a5c7b5c # Parent 3dc86d8eb0a9419e2a5391b0a93a786e6b6308dd Change ringbuffer functionality. diff -r 3dc86d8eb0a9 -r 18e292701db4 th_util.c --- a/th_util.c Thu Jun 09 20:48:17 2011 +0300 +++ b/th_util.c Thu Jun 09 22:29:40 2011 +0300 @@ -425,7 +425,8 @@ int i; for (i = 0; i < buf->n; i++) - buf->deallocator(buf->data[i]); + if (buf->data[i] != NULL) + buf->deallocator(buf->data[i]); th_free(buf->data); th_free(buf); @@ -434,13 +435,11 @@ void th_ringbuf_add(qringbuf_t *buf, void *ptr) { - if (buf->n < buf->size) { - buf->data[buf->n] = ptr; + if (buf->n < buf->size) buf->n++; - } else { - th_free(buf->data[0]); - memmove(&(buf->data[0]), &(buf->data[1]), buf->size - 1); - buf->data[buf->size - 1] = ptr; - } + + th_free(buf->data[0]); + memmove(&(buf->data[0]), &(buf->data[1]), buf->size - 1); + buf->data[buf->size - 1] = ptr; }