aboutsummaryrefslogtreecommitdiffstats
path: root/alc/backends
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2022-11-16 18:59:40 -0800
committerChris Robinson <[email protected]>2022-11-16 19:04:20 -0800
commit38d07b3b96f9494ce1ccebce309cd9832d32ac51 (patch)
treeb68d7eb11ceaecce712deeb0b23a33b6b808a651 /alc/backends
parent8ee842a948367bde4f323561acc899450126eaf7 (diff)
Avoid a use-after-free in the ALSA backend
Diffstat (limited to 'alc/backends')
-rw-r--r--alc/backends/alsa.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/alc/backends/alsa.cpp b/alc/backends/alsa.cpp
index b6efeaba..85f1824b 100644
--- a/alc/backends/alsa.cpp
+++ b/alc/backends/alsa.cpp
@@ -623,7 +623,7 @@ int AlsaPlayback::mixerNoMMapProc()
void AlsaPlayback::open(const char *name)
{
- const char *driver{"default"};
+ std::string driver{"default"};
if(name)
{
if(PlaybackDevices.empty())
@@ -634,21 +634,21 @@ void AlsaPlayback::open(const char *name)
if(iter == PlaybackDevices.cend())
throw al::backend_exception{al::backend_error::NoDevice,
"Device name \"%s\" not found", name};
- driver = iter->device_name.c_str();
+ driver = iter->device_name;
}
else
{
name = alsaDevice;
if(auto driveropt = ConfigValueStr(nullptr, "alsa", "device"))
- driver = driveropt->c_str();
+ driver = std::move(driveropt).value();
}
- TRACE("Opening device \"%s\"\n", driver);
+ TRACE("Opening device \"%s\"\n", driver.c_str());
snd_pcm_t *pcmHandle{};
- int err{snd_pcm_open(&pcmHandle, driver, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)};
+ int err{snd_pcm_open(&pcmHandle, driver.c_str(), 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};
+ "Could not open ALSA device \"%s\"", driver.c_str()};
if(mPcmHandle)
snd_pcm_close(mPcmHandle);
mPcmHandle = pcmHandle;
@@ -895,7 +895,7 @@ AlsaCapture::~AlsaCapture()
void AlsaCapture::open(const char *name)
{
- const char *driver{"default"};
+ std::string driver{"default"};
if(name)
{
if(CaptureDevices.empty())
@@ -906,20 +906,20 @@ void AlsaCapture::open(const char *name)
if(iter == CaptureDevices.cend())
throw al::backend_exception{al::backend_error::NoDevice,
"Device name \"%s\" not found", name};
- driver = iter->device_name.c_str();
+ driver = iter->device_name;
}
else
{
name = alsaDevice;
if(auto driveropt = ConfigValueStr(nullptr, "alsa", "capture"))
- driver = driveropt->c_str();
+ driver = std::move(driveropt).value();
}
- TRACE("Opening device \"%s\"\n", driver);
- int err{snd_pcm_open(&mPcmHandle, driver, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK)};
+ TRACE("Opening device \"%s\"\n", driver.c_str());
+ int err{snd_pcm_open(&mPcmHandle, driver.c_str(), SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK)};
if(err < 0)
throw al::backend_exception{al::backend_error::NoDevice,
- "Could not open ALSA device \"%s\"", driver};
+ "Could not open ALSA device \"%s\"", driver.c_str()};
/* Free alsa's global config tree. Otherwise valgrind reports a ton of leaks. */
snd_config_update_free_global();