Mercurial > hg > svcore
changeset 819:51cf0c35e9b0
Avoid deleting unallocated buffer in dtor
author | Chris Cannam |
---|---|
date | Mon, 08 Jul 2013 14:21:50 +0100 |
parents | f85050b6f522 |
children | bb7ea947c60d |
files | data/fileio/CoreAudioFileReader.cpp |
diffstat | 1 files changed, 12 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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; }