[pulseaudio-discuss] [PATCH v2] stream: Return error in case a client peeks to early

David Henningsson david.henningsson at canonical.com
Thu Oct 4 05:32:30 PDT 2012


If there is no silence memblock and no data, pa_memblockq_peek can
return NULL. In this case, do not crash on an assertion in
pa_memblock_acquire, but instead return NULL.

BugLink: http://bugs.launchpad.net/bugs/1058200
Signed-off-by: David Henningsson <david.henningsson at canonical.com>
---
 src/pulse/stream.c |    3 ++-
 src/pulse/stream.h |    4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/pulse/stream.c b/src/pulse/stream.c
index 2b6d306..0defb4f 100644
--- a/src/pulse/stream.c
+++ b/src/pulse/stream.c
@@ -1592,7 +1592,8 @@ int pa_stream_peek(pa_stream *s, const void **data, size_t *length) {
 
     if (!s->peek_memchunk.memblock) {
 
-        if (pa_memblockq_peek(s->record_memblockq, &s->peek_memchunk) < 0) {
+        if (pa_memblockq_peek(s->record_memblockq, &s->peek_memchunk) < 0 ||
+            !s->peek_memchunk.memblock) {
             *data = NULL;
             *length = 0;
             return 0;
diff --git a/src/pulse/stream.h b/src/pulse/stream.h
index b4464fa..8665d13 100644
--- a/src/pulse/stream.h
+++ b/src/pulse/stream.h
@@ -537,8 +537,8 @@ int pa_stream_write(
  * \a data will point to the actual data and \a nbytes will contain the size
  * of the data in bytes (which can be less or more than a complete
  * fragment). Use pa_stream_drop() to actually remove the data from
- * the buffer. If no data is available this will return a NULL
- * pointer. */
+ * the buffer. If no data is available (at the current read position)
+ * this will return a NULL pointer. */
 int pa_stream_peek(
         pa_stream *p                 /**< The stream to use */,
         const void **data            /**< Pointer to pointer that will point to data */,
-- 
1.7.9.5



More information about the pulseaudio-discuss mailing list