From 46eab05045d48e580bc2787da17e92f8d7d2846a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 1 Jul 2020 20:56:50 +0200 Subject: [PATCH] decoder/opus: allocate buffer only in the first chained song Fixes memory leak. That's what we get for --- NEWS | 1 + src/decoder/plugins/OpusDecoderPlugin.cxx | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 703ce8478..0f86d2431 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ ver 0.21.25 (not yet released) - smbclient: don't send credentials to MPD clients * decoder - opus: apply pre-skip + - opus: fix memory leak * output - osx: improve sample rate selection * Windows/Android: diff --git a/src/decoder/plugins/OpusDecoderPlugin.cxx b/src/decoder/plugins/OpusDecoderPlugin.cxx index 88e8098f0..fc77b5454 100644 --- a/src/decoder/plugins/OpusDecoderPlugin.cxx +++ b/src/decoder/plugins/OpusDecoderPlugin.cxx @@ -192,8 +192,12 @@ MPDOpusDecoder::OnOggBeginning(const ogg_packet &packet) client.Ready(audio_format, eos_granulepos > 0, duration); frame_size = audio_format.GetFrameSize(); - output_buffer = new opus_int16[opus_output_buffer_frames - * audio_format.channels]; + if (output_buffer == nullptr) + /* note: if we ever support changing the channel count + in chained streams, we need to reallocate this + buffer instead of keeping it */ + output_buffer = new opus_int16[opus_output_buffer_frames + * audio_format.channels]; auto cmd = client.GetCommand(); if (cmd != DecoderCommand::NONE)