From a6974a6c83dcb08735c1c88eb9c0050c084bb1e2 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 14 May 2014 21:20:28 -0700 Subject: Don't try to read the internal capture buffer into itself --- Alc/backends/alsa.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index d0677068..4b798b42 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -1128,11 +1128,12 @@ static void ALCcaptureAlsa_stop(ALCcaptureAlsa *self) void *ptr; size = snd_pcm_frames_to_bytes(self->pcmHandle, avail); - ptr = realloc(self->buffer, size); + ptr = malloc(size); if(ptr) { + ALCcaptureAlsa_captureSamples(self, ptr, avail); + free(self->buffer); self->buffer = ptr; - ALCcaptureAlsa_captureSamples(self, self->buffer, avail); self->size = size; } } @@ -1164,17 +1165,19 @@ static ALCenum ALCcaptureAlsa_captureSamples(ALCcaptureAlsa *self, ALCvoid *buff if((snd_pcm_uframes_t)amt > samples) amt = samples; amt = snd_pcm_frames_to_bytes(self->pcmHandle, amt); - memmove(buffer, self->buffer, amt); + memcpy(buffer, self->buffer, amt); if(self->size > amt) + { memmove(self->buffer, self->buffer+amt, self->size - amt); - else if(self->buffer != buffer) + self->size -= amt; + } + else { - /* 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