Fix potential double-free in ffmpegdecoder

This commit is contained in:
casey langen 2023-01-28 15:46:15 -08:00
parent 7af01b1d04
commit 0ead12be21
3 changed files with 8 additions and 9 deletions

View File

@ -1,5 +1,7 @@
0.99.5
* fixed a bug in `ffmpegdecoder` that could cause the app to crash when
releasing a stream.
* fixed unicode character parsing in musikcube-cmd.exe
* merged upstream PDCursesMod changes
* update essential build shell scripts to use `sh` instead of `bash` to improve

View File

@ -151,8 +151,6 @@ FfmpegDecoder::FfmpegDecoder() {
this->decodedFrame = nullptr;
this->resampledFrame = nullptr;
this->resampler = nullptr;
this->bufferSize = AV_INPUT_BUFFER_PADDING_SIZE + BUFFER_SIZE;
this->buffer = new unsigned char[this->bufferSize];
this->outputFifo = nullptr;
this->preferredSampleRate = -1;
}
@ -160,9 +158,6 @@ FfmpegDecoder::FfmpegDecoder() {
FfmpegDecoder::~FfmpegDecoder() {
this->Reset();
delete[] this->buffer;
this->buffer = nullptr;
if (this->decodedFrame) {
av_frame_free(&this->decodedFrame);
this->decodedFrame = nullptr;
@ -233,6 +228,7 @@ double FfmpegDecoder::GetDuration() {
void FfmpegDecoder::Reset() {
if (this->ioContext) {
av_free(this->ioContext->buffer);
av_free(this->ioContext);
this->ioContext = nullptr;
}
@ -295,9 +291,12 @@ bool FfmpegDecoder::Open(musik::core::sdk::IDataStream *stream) {
this->stream = stream;
const int ioContextBufferSize = AV_INPUT_BUFFER_PADDING_SIZE + BUFFER_SIZE;
unsigned char* ioContextBuffer = (unsigned char*) av_malloc(ioContextBufferSize);
this->ioContext = avio_alloc_context(
this->buffer,
(int) this->bufferSize,
ioContextBuffer,
ioContextBufferSize,
0,
this,
readCallback,

View File

@ -93,10 +93,8 @@ class FfmpegDecoder: public musik::core::sdk::IDecoder {
AVFrame* decodedFrame;
AVFrame* resampledFrame;
SwrContext* resampler;
unsigned char* buffer;
int preferredSampleRate { -1 };
bool disableInvalidPacketDetection { false };
int bufferSize;
int rate, channels;
int streamId;
int preferredFrameSize;