From f311f74001a30b3d1f518764a4dce2b9333ee60a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 14 May 2014 03:22:42 -0700 Subject: Avoid freeing an in-use capture buffer When stopping, ALSA may capture into its own storage buffer. Do not free the storage buffer if it first reads from it. --- Alc/backends/alsa.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'Alc') diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index 749db892..d0677068 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -1167,16 +1167,14 @@ static ALCenum ALCcaptureAlsa_captureSamples(ALCcaptureAlsa *self, ALCvoid *buff memmove(buffer, self->buffer, amt); if(self->size > amt) - { memmove(self->buffer, self->buffer+amt, self->size - amt); - self->size -= amt; - } - else + else if(self->buffer != buffer) { + /* Do not free the buffer if it's reading into itself. */ free(self->buffer); self->buffer = NULL; - self->size = 0; } + self->size -= amt; amt = snd_pcm_bytes_to_frames(self->pcmHandle, amt); } else if(self->doCapture) -- cgit v1.2.3