Skip to content

Commit

Permalink
SOUND: Clear temporary packet data after libvorbis call
Browse files Browse the repository at this point in the history
This fixes Coverity Scan issues #298733, #298734 and #298735.
  • Loading branch information
DrMcCoy committed Aug 29, 2020
1 parent 0baf9b9 commit 2df7222
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/sound/decoders/vorbis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@

#include <vorbis/vorbisfile.h>

#include <boost/scope_exit.hpp>

#include "src/common/disposableptr.h"
#include "src/common/util.h"
#include "src/common/readstream.h"
Expand Down Expand Up @@ -375,6 +377,10 @@ bool PacketizedVorbisStream::parseExtraData(Common::SeekableReadStream &stream)
}

for (int i = 0; i < 3; i++) {
BOOST_SCOPE_EXIT(&_packet) {
_packet.packet = nullptr;
} BOOST_SCOPE_EXIT_END

_packet.b_o_s = (i == 0);
_packet.bytes = headerSizes[i];
_packet.packet = headers[i].get();
Expand Down Expand Up @@ -412,6 +418,10 @@ bool PacketizedVorbisStream::parseExtraData(Common::SeekableReadStream &packet1,
#undef READ_WHOLE_STREAM

for (int i = 0; i < 3; i++) {
BOOST_SCOPE_EXIT(&_packet) {
_packet.packet = nullptr;
} BOOST_SCOPE_EXIT_END

_packet.b_o_s = (i == 0);
_packet.bytes = headerSizes[i];
_packet.packet = headers[i].get();
Expand Down Expand Up @@ -456,6 +466,10 @@ size_t PacketizedVorbisStream::readBuffer(int16_t *buffer, const size_t numSampl
std::unique_ptr<byte[]> data = std::make_unique<byte[]>(stream->size());
stream->read(data.get(), stream->size());

BOOST_SCOPE_EXIT(&_packet) {
_packet.packet = nullptr;
} BOOST_SCOPE_EXIT_END

// Synthesize!
_packet.packet = data.get();
_packet.bytes = stream->size();
Expand Down

0 comments on commit 2df7222

Please sign in to comment.