lib/file: Fix a potential memory leak created by yours truly
parent
f3e03710f6
commit
39c5940200
|
@ -61,10 +61,6 @@ bool File::eof() {
|
|||
}
|
||||
|
||||
ErrorOr<uint8_t> File::readByte(){
|
||||
uint8_t* nextPointer = new uint8_t;
|
||||
uint8_t nextByte;
|
||||
bool failure = false;
|
||||
|
||||
if (!this->isOpen) {
|
||||
return ErrorOr<uint8_t>(true, ErrorCodes::FILE_NOT_OPEN);
|
||||
}
|
||||
|
@ -72,6 +68,10 @@ ErrorOr<uint8_t> File::readByte(){
|
|||
return ErrorOr<uint8_t>(true, ErrorCodes::OVERRUN);
|
||||
}
|
||||
|
||||
uint8_t* nextPointer = new uint8_t;
|
||||
uint8_t nextByte;
|
||||
bool failure = false;
|
||||
|
||||
try {
|
||||
this->fileStream.seekg(this->cursorPosition);
|
||||
this->fileStream.read(reinterpret_cast<char*>(nextPointer), 1);
|
||||
|
@ -87,10 +87,6 @@ ErrorOr<uint8_t> File::readByte(){
|
|||
}
|
||||
|
||||
ErrorOr<std::vector<uint8_t>> File::read(uint64_t bytes){
|
||||
uint8_t* buffer = new uint8_t[bytes];
|
||||
std::vector<uint8_t> data;
|
||||
bool failure = false;
|
||||
|
||||
if (!this->isOpen) {
|
||||
return ErrorOr<std::vector<uint8_t>>(true, ErrorCodes::FILE_NOT_OPEN);
|
||||
}
|
||||
|
@ -98,6 +94,10 @@ ErrorOr<std::vector<uint8_t>> File::read(uint64_t bytes){
|
|||
return ErrorOr<std::vector<uint8_t>>(true, ErrorCodes::OVERRUN);
|
||||
}
|
||||
|
||||
uint8_t* buffer = new uint8_t[bytes];
|
||||
std::vector<uint8_t> data;
|
||||
bool failure = false;
|
||||
|
||||
try {
|
||||
this->fileStream.seekg(this->cursorPosition);
|
||||
this->fileStream.read(reinterpret_cast<char*>(buffer), bytes);
|
||||
|
|
Loading…
Reference in New Issue