mirror of https://github.com/ARMmbed/mbed-os.git
HeapBlockDevice::erase(): free up heap memory
`HeapBlockDevice::erase()` previously performed a range and alignment check only. This commit adds freeing of heap memory.pull/14483/head
parent
7ef9e6175f
commit
6b5e467f96
|
|
@ -28,9 +28,11 @@
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
|
|
||||||
/** Lazily allocated heap-backed block device
|
/** Lazily allocated heap-backed block device.
|
||||||
*
|
*
|
||||||
* Useful for simulating a block device and tests
|
* Useful for simulating a block device and tests.
|
||||||
|
*
|
||||||
|
* @note Each block is allocated when used, and freed when erased.
|
||||||
*
|
*
|
||||||
* @code
|
* @code
|
||||||
* #include "mbed.h"
|
* #include "mbed.h"
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ HeapBlockDevice::~HeapBlockDevice()
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] _blocks;
|
delete[] _blocks;
|
||||||
_blocks = 0;
|
_blocks = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ int HeapBlockDevice::init()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < _count; i++) {
|
for (size_t i = 0; i < _count; i++) {
|
||||||
_blocks[i] = 0;
|
_blocks[i] = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,6 +184,13 @@ int HeapBlockDevice::erase(bd_addr_t addr, bd_size_t size)
|
||||||
if (!is_valid_erase(addr, size)) {
|
if (!is_valid_erase(addr, size)) {
|
||||||
return BD_ERROR_DEVICE_ERROR;
|
return BD_ERROR_DEVICE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < (size / _erase_size); i++) {
|
||||||
|
size_t index = addr / _erase_size + i;
|
||||||
|
delete[] _blocks[index];
|
||||||
|
_blocks[index] = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue