Skip to content

Commit

Permalink
decoder/opus: allocate buffer only in the first chained song
Browse files Browse the repository at this point in the history
Fixes memory leak.  That's what we get for
  • Loading branch information
MaxKellermann committed Jul 1, 2020
1 parent 5ca137c commit 46eab05
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions src/decoder/plugins/OpusDecoderPlugin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 46eab05

Please sign in to comment.