Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions libraries/Update/src/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,15 @@ UpdateClass& UpdateClass::onProgress(THandlerFunction_Progress fn) {
}

void UpdateClass::_reset() {
if (_buffer)
if (_buffer) {
delete[] _buffer;
_buffer = 0;
}
if (_skipBuffer) {
delete[] _skipBuffer;
}

_buffer = nullptr;
_skipBuffer = nullptr;
_bufferLen = 0;
_progress = 0;
_size = 0;
Expand Down Expand Up @@ -159,8 +165,8 @@ bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn, con
}

//initialize
_buffer = (uint8_t*)malloc(SPI_FLASH_SEC_SIZE);
if(!_buffer){
_buffer = new (std::nothrow) uint8_t[SPI_FLASH_SEC_SIZE];
if (!_buffer) {
log_e("malloc failed");
return false;
}
Expand Down Expand Up @@ -193,10 +199,10 @@ bool UpdateClass::_writeBuffer(){
//not written at this point so that partially written firmware
//will not be bootable
skip = ENCRYPTED_BLOCK_SIZE;
_skipBuffer = (uint8_t*)malloc(skip);
if(!_skipBuffer){
_skipBuffer = new (std::nothrow) uint8_t[skip];
if (!_skipBuffer) {
log_e("malloc failed");
return false;
return false;
}
memcpy(_skipBuffer, _buffer, skip);
}
Expand Down