Skip to content
Snippets Groups Projects
Commit dda278a2 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #8968: audiofile: fix memory leak on exception

Use vector<char> instead of char array for fileBuffer
parent fd30c61b
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,8 @@
#include <math.h>
#include <samplerate.h>
#include <cstring>
#include <limits.h>
#include <vector>
#include <climits>
#include "audiofile.h"
#include "audio/codecs/audiocodecfactory.h"
......@@ -62,8 +63,8 @@ RawFile::RawFile(const std::string& name, sfl::AudioCodec* codec, unsigned int s
size_t length = file.tellg();
file.seekg(0, std::ios::beg);
char *fileBuffer = new char[length];
file.read(fileBuffer,length);
std::vector<char> fileBuffer(length);
file.read(&fileBuffer[0], length);
file.close();
const unsigned int frameSize = audioCodec_->getFrameSize();
......@@ -74,7 +75,7 @@ RawFile::RawFile(const std::string& name, sfl::AudioCodec* codec, unsigned int s
SFLDataFormat *monoBuffer = new SFLDataFormat[decodedSize];
SFLDataFormat *bufpos = monoBuffer;
unsigned char *filepos = reinterpret_cast<unsigned char *>(fileBuffer);
unsigned char *filepos = reinterpret_cast<unsigned char *>(&fileBuffer[0]);
size_ = decodedSize;
while (length >= encFrameSize) {
......@@ -83,8 +84,6 @@ RawFile::RawFile(const std::string& name, sfl::AudioCodec* codec, unsigned int s
length -= encFrameSize;
}
delete [] fileBuffer;
if (sampleRate == audioRate)
buffer_ = monoBuffer;
else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment