mirror of
https://github.com/Ryujinx/libsoundio.git
synced 2024-12-22 18:25:35 +00:00
fix double clean up corruption when opening stream fails
affects ALSA, CoreAudio, JACK, WASAPI, and Dummy.
This commit is contained in:
parent
05a4280e52
commit
db0e3d136c
20
src/alsa.cpp
20
src/alsa.cpp
|
@ -927,14 +927,22 @@ static void outstream_destroy_alsa(SoundIoPrivate *si, SoundIoOutStreamPrivate *
|
|||
if (osa->thread) {
|
||||
osa->thread_exit_flag.clear();
|
||||
soundio_os_thread_destroy(osa->thread);
|
||||
osa->thread = nullptr;
|
||||
}
|
||||
|
||||
if (osa->handle)
|
||||
if (osa->handle) {
|
||||
snd_pcm_close(osa->handle);
|
||||
osa->handle = nullptr;
|
||||
}
|
||||
|
||||
free(osa->poll_fds);
|
||||
osa->poll_fds = nullptr;
|
||||
|
||||
free(osa->chmap);
|
||||
osa->chmap = nullptr;
|
||||
|
||||
free(osa->sample_buffer);
|
||||
osa->sample_buffer = nullptr;
|
||||
}
|
||||
|
||||
static int outstream_xrun_recovery(SoundIoOutStreamPrivate *os, int err) {
|
||||
|
@ -1502,14 +1510,22 @@ static void instream_destroy_alsa(SoundIoPrivate *si, SoundIoInStreamPrivate *is
|
|||
if (isa->thread) {
|
||||
isa->thread_exit_flag.clear();
|
||||
soundio_os_thread_destroy(isa->thread);
|
||||
isa->thread = nullptr;
|
||||
}
|
||||
|
||||
if (isa->handle)
|
||||
if (isa->handle) {
|
||||
snd_pcm_close(isa->handle);
|
||||
isa->handle = nullptr;
|
||||
}
|
||||
|
||||
free(isa->poll_fds);
|
||||
isa->poll_fds = nullptr;
|
||||
|
||||
free(isa->chmap);
|
||||
isa->chmap = nullptr;
|
||||
|
||||
free(isa->sample_buffer);
|
||||
isa->sample_buffer = nullptr;
|
||||
}
|
||||
|
||||
static int instream_open_alsa(SoundIoPrivate *si, SoundIoInStreamPrivate *is) {
|
||||
|
|
|
@ -890,6 +890,7 @@ static void outstream_destroy_ca(struct SoundIoPrivate *si, struct SoundIoOutStr
|
|||
if (osca->instance) {
|
||||
AudioOutputUnitStop(osca->instance);
|
||||
AudioComponentInstanceDispose(osca->instance);
|
||||
osca->instance = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1098,9 +1099,11 @@ static void instream_destroy_ca(struct SoundIoPrivate *si, struct SoundIoInStrea
|
|||
if (isca->instance) {
|
||||
AudioOutputUnitStop(isca->instance);
|
||||
AudioComponentInstanceDispose(isca->instance);
|
||||
isca->instance = nullptr;
|
||||
}
|
||||
|
||||
free(isca->buffer_list);
|
||||
isca->buffer_list = nullptr;
|
||||
}
|
||||
|
||||
static OSStatus read_callback_ca(void *userdata, AudioUnitRenderActionFlags *io_action_flags,
|
||||
|
|
|
@ -366,6 +366,7 @@ static void outstream_destroy_jack(struct SoundIoPrivate *is, struct SoundIoOutS
|
|||
SoundIoOutStreamJack *osj = &os->backend_data.jack;
|
||||
|
||||
jack_client_close(osj->client);
|
||||
osj->client = nullptr;
|
||||
}
|
||||
|
||||
static SoundIoDeviceJackPort *find_port_matching_channel(SoundIoDevice *device, SoundIoChannelId id) {
|
||||
|
@ -591,6 +592,7 @@ static void instream_destroy_jack(struct SoundIoPrivate *si, struct SoundIoInStr
|
|||
SoundIoInStreamJack *isj = &is->backend_data.jack;
|
||||
|
||||
jack_client_close(isj->client);
|
||||
isj->client = nullptr;
|
||||
}
|
||||
|
||||
static int instream_xrun_callback(void *arg) {
|
||||
|
|
|
@ -720,6 +720,8 @@ int soundio_os_init_mirrored_memory(struct SoundIoOsMirroredMemory *mem, size_t
|
|||
}
|
||||
|
||||
void soundio_os_deinit_mirrored_memory(struct SoundIoOsMirroredMemory *mem) {
|
||||
if (!mem->address)
|
||||
return;
|
||||
#if defined(SOUNDIO_OS_WINDOWS)
|
||||
BOOL ok;
|
||||
ok = UnmapViewOfFile(mem->address);
|
||||
|
@ -732,4 +734,5 @@ void soundio_os_deinit_mirrored_memory(struct SoundIoOsMirroredMemory *mem) {
|
|||
int err = munmap(mem->address, 2 * mem->capacity);
|
||||
assert(!err);
|
||||
#endif
|
||||
mem->address = nullptr;
|
||||
}
|
||||
|
|
|
@ -1058,16 +1058,26 @@ static void outstream_destroy_wasapi(struct SoundIoPrivate *si, struct SoundIoOu
|
|||
soundio_os_mutex_unlock(osw->mutex);
|
||||
|
||||
soundio_os_thread_destroy(osw->thread);
|
||||
|
||||
osw->thread = nullptr;
|
||||
}
|
||||
|
||||
if (osw->h_event)
|
||||
if (osw->h_event) {
|
||||
CloseHandle(osw->h_event);
|
||||
osw->h_event = nullptr;
|
||||
}
|
||||
|
||||
free(osw->stream_name);
|
||||
osw->stream_name = nullptr;
|
||||
|
||||
soundio_os_cond_destroy(osw->cond);
|
||||
osw->cond = nullptr;
|
||||
|
||||
soundio_os_cond_destroy(osw->start_cond);
|
||||
osw->start_cond = nullptr;
|
||||
|
||||
soundio_os_mutex_destroy(osw->mutex);
|
||||
osw->mutex = nullptr;
|
||||
}
|
||||
|
||||
static int outstream_do_open(SoundIoPrivate *si, SoundIoOutStreamPrivate *os) {
|
||||
|
@ -1572,14 +1582,23 @@ static void instream_destroy_wasapi(struct SoundIoPrivate *si, struct SoundIoInS
|
|||
soundio_os_cond_signal(isw->start_cond, isw->mutex);
|
||||
soundio_os_mutex_unlock(isw->mutex);
|
||||
soundio_os_thread_destroy(isw->thread);
|
||||
|
||||
isw->thread = nullptr;
|
||||
}
|
||||
|
||||
if (isw->h_event)
|
||||
if (isw->h_event) {
|
||||
CloseHandle(isw->h_event);
|
||||
isw->h_event = nullptr;
|
||||
}
|
||||
|
||||
soundio_os_cond_destroy(isw->cond);
|
||||
isw->cond = nullptr;
|
||||
|
||||
soundio_os_cond_destroy(isw->start_cond);
|
||||
isw->start_cond = nullptr;
|
||||
|
||||
soundio_os_mutex_destroy(isw->mutex);
|
||||
isw->mutex = nullptr;
|
||||
}
|
||||
|
||||
static int instream_do_open(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) {
|
||||
|
|
Loading…
Reference in a new issue