Don't try to read the internal capture buffer into itself
This commit is contained in:
parent
a1fbb434e8
commit
a6974a6c83
@ -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)
|
||||
{
|
||||
/* Do not free the buffer if it's reading into itself. */
|
||||
memmove(self->buffer, self->buffer+amt, self->size - amt);
|
||||
self->size -= amt;
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user