From f9750875e332a4ccf2c19745920a2cbc7dfc652f Mon Sep 17 00:00:00 2001 From: xperia64 Date: Thu, 21 May 2020 20:34:00 -0400 Subject: [PATCH 1/2] Avoid leaking the cubeb input stream --- src/audio_core/cubeb_input.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/audio_core/cubeb_input.cpp b/src/audio_core/cubeb_input.cpp index 794c367aba..c96e13395d 100644 --- a/src/audio_core/cubeb_input.cpp +++ b/src/audio_core/cubeb_input.cpp @@ -37,7 +37,7 @@ CubebInput::~CubebInput() { if (!impl->ctx) return; - if (cubeb_stream_stop(impl->stream) != CUBEB_OK) { + if (impl->stream && cubeb_stream_stop(impl->stream) != CUBEB_OK) { LOG_ERROR(Audio, "Error stopping cubeb input stream."); } @@ -103,8 +103,11 @@ void CubebInput::StartSampling(const Frontend::Mic::Parameters& params) { } void CubebInput::StopSampling() { + // TODO(xperia64): Destroy the stream for now to avoid a leak because StartSampling reinitializes the stream every time if (impl->stream) { cubeb_stream_stop(impl->stream); + cubeb_stream_destroy(impl->stream); + impl->stream = nullptr; } is_sampling = false; } From 21159dd83a6756b7efc35090684453d96b5fd6ef Mon Sep 17 00:00:00 2001 From: xperia64 Date: Thu, 21 May 2020 21:05:03 -0400 Subject: [PATCH 2/2] clang-format, and avoid another potential leak --- src/audio_core/cubeb_input.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/audio_core/cubeb_input.cpp b/src/audio_core/cubeb_input.cpp index c96e13395d..04d89e5259 100644 --- a/src/audio_core/cubeb_input.cpp +++ b/src/audio_core/cubeb_input.cpp @@ -37,8 +37,12 @@ CubebInput::~CubebInput() { if (!impl->ctx) return; - if (impl->stream && cubeb_stream_stop(impl->stream) != CUBEB_OK) { - LOG_ERROR(Audio, "Error stopping cubeb input stream."); + if (impl->stream) { + if (cubeb_stream_stop(impl->stream) != CUBEB_OK) { + LOG_ERROR(Audio, "Error stopping cubeb input stream."); + } + + cubeb_stream_destroy(impl->stream); } cubeb_destroy(impl->ctx); @@ -103,7 +107,8 @@ void CubebInput::StartSampling(const Frontend::Mic::Parameters& params) { } void CubebInput::StopSampling() { - // TODO(xperia64): Destroy the stream for now to avoid a leak because StartSampling reinitializes the stream every time + // TODO(xperia64): Destroy the stream for now to avoid a leak because StartSampling + // reinitializes the stream every time if (impl->stream) { cubeb_stream_stop(impl->stream); cubeb_stream_destroy(impl->stream);