diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/buffering.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/apps/buffering.c b/apps/buffering.c index b527264a6e..97f85dfbc7 100644 --- a/apps/buffering.c +++ b/apps/buffering.c | |||
@@ -231,9 +231,20 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap, | |||
231 | 231 | ||
232 | mutex_lock(&llist_mutex); | 232 | mutex_lock(&llist_mutex); |
233 | 233 | ||
234 | /* Allocate the remainder of the space for the current handle */ | 234 | if (cur_handle && cur_handle->filerem > 0) { |
235 | if (cur_handle) | 235 | /* the current handle hasn't finished buffering. We can only add |
236 | new_widx = RINGBUF_ADD(cur_handle->widx, cur_handle->filerem); | 236 | a new one if there is already enough free space to finish |
237 | the buffering. */ | ||
238 | size_t req = cur_handle->filerem + sizeof(struct memory_handle); | ||
239 | if (RINGBUF_ADD_CROSS(cur_handle->widx, req, buf_ridx) >= 0) { | ||
240 | /* Not enough space */ | ||
241 | mutex_unlock(&llist_mutex); | ||
242 | return NULL; | ||
243 | } else { | ||
244 | /* Allocate the remainder of the space for the current handle */ | ||
245 | new_widx = RINGBUF_ADD(cur_handle->widx, cur_handle->filerem); | ||
246 | } | ||
247 | } | ||
237 | 248 | ||
238 | /* align buf_widx to 4 bytes up */ | 249 | /* align buf_widx to 4 bytes up */ |
239 | new_widx = (RINGBUF_ADD(new_widx, 3)) & ~3; | 250 | new_widx = (RINGBUF_ADD(new_widx, 3)) & ~3; |