Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

buffering.c: Fix oopses with caching handle pointer

The location of the handle cannot be kept across calls to
shrink_handle() since it may move the structure. The error was
there in one place at the inception, corrected, then reintroduced.

Make shrink_handle() return the new location and use it, which
makes the side effects of the function clearer.

Change-Id: Icae6a0ad6f7bb0d6645b044cccfa4aef88db42ad

+9 -8
+9 -8
apps/buffering.c
··· 742 742 743 743 /* Free buffer space by moving the handle struct right before the useful 744 744 part of its data buffer or by moving all the data. */ 745 - static void shrink_handle(struct memory_handle *h) 745 + static struct memory_handle * shrink_handle(struct memory_handle *h) 746 746 { 747 747 if (!h) 748 - return; 748 + return NULL; 749 749 750 750 if (h->type == TYPE_PACKET_AUDIO) { 751 751 /* only move the handle struct */ ··· 756 756 757 757 /* The value of delta might change for alignment reasons */ 758 758 if (!move_handle(&h, &delta, 0)) 759 - return; 759 + return h; 760 760 761 761 h->data = ringbuf_add(h->data, delta); 762 762 h->start += delta; 763 763 } else { 764 764 /* metadata handle: we can move all of it */ 765 765 if (h->pinned || !HLIST_NEXT(h)) 766 - return; /* Pinned, last handle */ 766 + return h; /* Pinned, last handle */ 767 767 768 768 size_t data_size = h->filesize - h->start; 769 769 uintptr_t handle_distance = ··· 772 772 773 773 /* The value of delta might change for alignment reasons */ 774 774 if (!move_handle(&h, &delta, data_size)) 775 - return; 775 + return h; 776 776 777 777 size_t olddata = h->data; 778 778 h->data = ringbuf_add(h->data, delta); ··· 799 799 break; 800 800 } 801 801 } 802 + 803 + return h; 802 804 } 803 805 804 806 /* Fill the buffer by buffering as much data as possible for handles that still ··· 809 811 logf("fill_buffer()"); 810 812 mutex_lock(&llist_mutex); 811 813 812 - struct memory_handle *m = HLIST_FIRST; 813 - shrink_handle(m); 814 + struct memory_handle *m = shrink_handle(HLIST_FIRST); 814 815 815 816 mutex_unlock(&llist_mutex); 816 817 ··· 1593 1594 mutex_lock(&llist_mutex); 1594 1595 1595 1596 for (struct memory_handle *h = HLIST_LAST; h; h = HLIST_PREV(h)) { 1596 - shrink_handle(h); 1597 + h = shrink_handle(h); 1597 1598 } 1598 1599 1599 1600 mutex_unlock(&llist_mutex);