From 0ebfb937aaa073282415e561f8d1f150813a00fd Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Mon, 21 May 2012 02:18:46 -0400 Subject: Fix some lockup caused by handles not being initialized to < 0... ...by default where they would be interpreted as valid but not actually be which would cause calls to buffering while it was not initialized. Add BUFFER_EVENT_BUFFER_RESET to inform users of buffering that the buffer is being reinitialized. Basically, this wraps all the functionality being provided by three events (...START_PLAYBACK, RECORDING_EVENT_START, RECORDING_EVENT_STOP) into one for radioart.c, the only user of those events (perhaps remove them?) and closes some loopholes. Change-Id: I99ec46b9b5fb4e36605db5944c60ed986163db3a --- apps/buffering.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'apps/buffering.c') diff --git a/apps/buffering.c b/apps/buffering.c index c47564b..b5bf427 100644 --- a/apps/buffering.c +++ b/apps/buffering.c @@ -389,7 +389,7 @@ static bool rm_handle(const struct memory_handle *h) NULL if the handle wasn't found */ static struct memory_handle *find_handle(int handle_id) { - if (handle_id < 0) + if (handle_id < 0 || !first_handle) return NULL; /* simple caching because most of the time the requested handle @@ -1748,12 +1748,22 @@ bool buffering_reset(char *buf, size_t buflen) thus buf and buflen must be a aligned to an integer multiple of the storage alignment */ - buflen -= GUARD_BUFSIZE; + if (buf) { + buflen -= MIN(buflen, GUARD_BUFSIZE); + + STORAGE_ALIGN_BUFFER(buf, buflen); - STORAGE_ALIGN_BUFFER(buf, buflen); + if (!buf || !buflen) + return false; + } else { + buflen = 0; + } - if (!buf || !buflen) - return false; + send_event(BUFFER_EVENT_BUFFER_RESET, NULL); + + /* If handles weren't closed above, just do it */ + while (num_handles != 0) + bufclose(first_handle->id); buffer = buf; buffer_len = buflen; -- cgit v1.1