diff options
Diffstat (limited to 'alc/backends/alsa.cpp')
-rw-r--r-- | alc/backends/alsa.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp index bdfdd040..6a7a1187 100644 --- a/alc/backends/alsa.cpp +++ b/alc/backends/alsa.cpp @@ -635,12 +635,16 @@ void AlsaPlayback::open(const char *name) name = alsaDevice; driver = GetConfigValue(nullptr, "alsa", "device", "default"); } - TRACE("Opening device \"%s\"\n", driver); - int err{snd_pcm_open(&mPcmHandle, driver, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)}; + + snd_pcm_t *pcmHandle{}; + int err{snd_pcm_open(&pcmHandle, driver, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)}; if(err < 0) throw al::backend_exception{al::backend_error::NoDevice, "Could not open ALSA device \"%s\"", driver}; + if(mPcmHandle) + snd_pcm_close(mPcmHandle); + mPcmHandle = pcmHandle; /* Free alsa's global config tree. Otherwise valgrind reports a ton of leaks. */ snd_config_update_free_global(); |