Mercurial > hg > svcore
comparison data/fileio/CoreAudioFileReader.cpp @ 819:51cf0c35e9b0
Avoid deleting unallocated buffer in dtor
author | Chris Cannam |
---|---|
date | Mon, 08 Jul 2013 14:21:50 +0100 |
parents | 12f78ebc82bf |
children | 54829c1e155e e802e550a1f2 |
comparison
equal
deleted
inserted
replaced
811:f85050b6f522 | 819:51cf0c35e9b0 |
---|---|
31 #endif | 31 #endif |
32 | 32 |
33 class CoreAudioFileReader::D | 33 class CoreAudioFileReader::D |
34 { | 34 { |
35 public: | 35 public: |
36 D() : blockSize(1024) { } | 36 D() : blockSize(1024), valid(false) { } |
37 | 37 |
38 ExtAudioFileRef file; | 38 ExtAudioFileRef file; |
39 AudioBufferList buffer; | 39 AudioBufferList buffer; |
40 OSStatus err; | 40 OSStatus err; |
41 AudioStreamBasicDescription asbd; | 41 AudioStreamBasicDescription asbd; |
42 int blockSize; | 42 int blockSize; |
43 bool valid; | |
43 }; | 44 }; |
44 | 45 |
45 static QString | 46 static QString |
46 codestr(OSStatus err) | 47 codestr(OSStatus err) |
47 { | 48 { |
114 m_d->err = ExtAudioFileGetProperty | 115 m_d->err = ExtAudioFileGetProperty |
115 (m_d->file, kExtAudioFileProperty_FileDataFormat, &propsize, &m_d->asbd); | 116 (m_d->file, kExtAudioFileProperty_FileDataFormat, &propsize, &m_d->asbd); |
116 | 117 |
117 if (m_d->err) { | 118 if (m_d->err) { |
118 m_error = "CoreAudioReadStream: Error in getting basic description: code " + codestr(m_d->err); | 119 m_error = "CoreAudioReadStream: Error in getting basic description: code " + codestr(m_d->err); |
120 ExtAudioFileDispose(m_d->file); | |
119 return; | 121 return; |
120 } | 122 } |
121 | 123 |
122 m_channelCount = m_d->asbd.mChannelsPerFrame; | 124 m_channelCount = m_d->asbd.mChannelsPerFrame; |
123 m_fileRate = m_d->asbd.mSampleRate; | 125 m_fileRate = m_d->asbd.mSampleRate; |
138 m_d->err = ExtAudioFileSetProperty | 140 m_d->err = ExtAudioFileSetProperty |
139 (m_d->file, kExtAudioFileProperty_ClientDataFormat, propsize, &m_d->asbd); | 141 (m_d->file, kExtAudioFileProperty_ClientDataFormat, propsize, &m_d->asbd); |
140 | 142 |
141 if (m_d->err) { | 143 if (m_d->err) { |
142 m_error = "CoreAudioReadStream: Error in setting client format: code " + codestr(m_d->err); | 144 m_error = "CoreAudioReadStream: Error in setting client format: code " + codestr(m_d->err); |
145 ExtAudioFileDispose(m_d->file); | |
143 return; | 146 return; |
144 } | 147 } |
145 | 148 |
146 m_d->buffer.mNumberBuffers = 1; | 149 m_d->buffer.mNumberBuffers = 1; |
147 m_d->buffer.mBuffers[0].mNumberChannels = m_channelCount; | 150 m_d->buffer.mBuffers[0].mNumberChannels = m_channelCount; |
148 m_d->buffer.mBuffers[0].mDataByteSize = sizeof(float) * m_channelCount * m_d->blockSize; | 151 m_d->buffer.mBuffers[0].mDataByteSize = sizeof(float) * m_channelCount * m_d->blockSize; |
149 m_d->buffer.mBuffers[0].mData = new float[m_channelCount * m_d->blockSize]; | 152 m_d->buffer.mBuffers[0].mData = new float[m_channelCount * m_d->blockSize]; |
153 | |
154 m_d->valid = true; | |
150 | 155 |
151 initialiseDecodeCache(); | 156 initialiseDecodeCache(); |
152 | 157 |
153 if (m_reporter) { | 158 if (m_reporter) { |
154 connect(m_reporter, SIGNAL(cancelled()), this, SLOT(cancelled())); | 159 connect(m_reporter, SIGNAL(cancelled()), this, SLOT(cancelled())); |
179 | 184 |
180 finishDecodeCache(); | 185 finishDecodeCache(); |
181 endSerialised(); | 186 endSerialised(); |
182 | 187 |
183 m_completion = 100; | 188 m_completion = 100; |
184 | |
185 ExtAudioFileDispose(m_d->file); | |
186 } | 189 } |
187 | 190 |
188 | 191 |
189 CoreAudioFileReader::~CoreAudioFileReader() | 192 CoreAudioFileReader::~CoreAudioFileReader() |
190 { | 193 { |
191 std::cerr << "CoreAudioFileReader::~CoreAudioFileReader" << std::endl; | 194 std::cerr << "CoreAudioFileReader::~CoreAudioFileReader" << std::endl; |
192 delete[] m_d->buffer.mBuffers[0].mData; | 195 |
196 if (m_d->valid) { | |
197 ExtAudioFileDispose(m_d->file); | |
198 delete[] m_d->buffer.mBuffers[0].mData; | |
199 } | |
200 | |
193 delete m_d; | 201 delete m_d; |
194 } | 202 } |
195 | 203 |
196 void | 204 void |
197 CoreAudioFileReader::cancelled() | 205 CoreAudioFileReader::cancelled() |