# HG changeset patch # User Chris Cannam # Date 1373289710 -3600 # Node ID 51cf0c35e9b0aded07c58708e95bd77218909cc8 # Parent f85050b6f5229c083f639811aa39a87c8afa7820 Avoid deleting unallocated buffer in dtor diff -r f85050b6f522 -r 51cf0c35e9b0 data/fileio/CoreAudioFileReader.cpp --- a/data/fileio/CoreAudioFileReader.cpp Thu May 16 14:13:46 2013 +0100 +++ b/data/fileio/CoreAudioFileReader.cpp Mon Jul 08 14:21:50 2013 +0100 @@ -33,13 +33,14 @@ class CoreAudioFileReader::D { public: - D() : blockSize(1024) { } + D() : blockSize(1024), valid(false) { } ExtAudioFileRef file; AudioBufferList buffer; OSStatus err; AudioStreamBasicDescription asbd; int blockSize; + bool valid; }; static QString @@ -116,6 +117,7 @@ if (m_d->err) { m_error = "CoreAudioReadStream: Error in getting basic description: code " + codestr(m_d->err); + ExtAudioFileDispose(m_d->file); return; } @@ -140,6 +142,7 @@ if (m_d->err) { m_error = "CoreAudioReadStream: Error in setting client format: code " + codestr(m_d->err); + ExtAudioFileDispose(m_d->file); return; } @@ -148,6 +151,8 @@ m_d->buffer.mBuffers[0].mDataByteSize = sizeof(float) * m_channelCount * m_d->blockSize; m_d->buffer.mBuffers[0].mData = new float[m_channelCount * m_d->blockSize]; + m_d->valid = true; + initialiseDecodeCache(); if (m_reporter) { @@ -181,15 +186,18 @@ endSerialised(); m_completion = 100; - - ExtAudioFileDispose(m_d->file); } CoreAudioFileReader::~CoreAudioFileReader() { std::cerr << "CoreAudioFileReader::~CoreAudioFileReader" << std::endl; - delete[] m_d->buffer.mBuffers[0].mData; + + if (m_d->valid) { + ExtAudioFileDispose(m_d->file); + delete[] m_d->buffer.mBuffers[0].mData; + } + delete m_d; }