From ba1b63a4352c3c6cab3ef716fded14fe3c11c064 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Wed, 22 Jun 2016 15:39:06 -0400 Subject: [PATCH] Bug1223 again: redo the fix exactly as Roger Dannenberg wants it --- lib-src/libnyquist/nyquist/nyqsrc/sound.c | 57 +++++++++++------------ 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/lib-src/libnyquist/nyquist/nyqsrc/sound.c b/lib-src/libnyquist/nyquist/nyqsrc/sound.c index ae498f41a..84803fdc3 100644 --- a/lib-src/libnyquist/nyquist/nyqsrc/sound.c +++ b/lib-src/libnyquist/nyquist/nyqsrc/sound.c @@ -515,43 +515,38 @@ void snd_list_terminate(snd_list) void snd_list_unref(snd_list_type list) { - void (*freefunc)(); - if (list == NULL) { nyquist_printf("why did snd_list_unref get %p?\n", list); return; } - while (! (list == NULL || list == zero_snd_list) ) { - list->refcnt--; - /* nyquist_printf("snd_list_unref "); print_snd_list_type(list); stdputstr("\n"); */ - if (list->refcnt == 0) { - snd_list_type next; - if (list->block && list->block != zero_block) { - /* there is a next snd_list */ - next = list->u.next; - /* stdputstr("["); */ - sample_block_unref(list->block); - /* stdputstr("]"); */ - } - else if (list->block == NULL) { /* the next thing is the susp */ - /* free suspension structure */ - /* nyquist_printf("freeing susp@%p\n", list->u.susp); */ - freefunc = list->u.susp->free; - (*freefunc)(list->u.susp); - next = NULL; - } - /* nyquist_printf("freeing snd_list@%p\n", list); */ - //DBY - if (list == list_watch) printf("freeing watched snd_list %p\n", list); - //DBY - ffree_snd_list(list, "snd_list_unref"); + while (list && (list != zero_snd_list)) { + snd_list_type next; - list = next; - } - else - break; - } + list->refcnt--; + if (list->refcnt != 0) { + break; // the rest of the list is shared, nothing more to free + } + + // list nodes either point to a block of samples or this is the + // last list node (list->block == NULL) which points to a suspension + // lists can also terminate at the zero_block, which is an infinite + // shared list (zero_block->block == zero_block) of zero samples + if (list->block && list->block != zero_block) { + /* there is a next snd_list */ + next = list->u.next; + sample_block_unref(list->block); + } else if (list->block == NULL) { /* the next thing is the susp */ + /* free suspension structure */ + /* nyquist_printf("freeing susp@%p\n", list->u.susp); */ + (*(list->u.susp->free))(list->u.susp); + next = NULL; + } + /* if (list == list_watch) + printf("freeing watched snd_list %p\n", list); */ + ffree_snd_list(list, "snd_list_unref"); + list = next; + } }