diff options
author | Chris Robinson <[email protected]> | 2014-05-14 21:20:28 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-05-14 21:20:28 -0700 |
commit | a6974a6c83dcb08735c1c88eb9c0050c084bb1e2 (patch) | |
tree | 8ccae6f2487ead9ad5698d303359644eed70138c /Alc/backends | |
parent | a1fbb434e80e95e42e1a484a4187fb313b264406 (diff) |
Don't try to read the internal capture buffer into itself
Diffstat (limited to 'Alc/backends')
-rw-r--r-- | Alc/backends/alsa.c | 15 |
1 files 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) |