kopia lustrzana https://github.com/espressif/esp-idf
esp32: modify realloc behaves just like malloc when pass a null pointer for ptr.
rodzic
add32cbc9a
commit
47db66e495
|
@ -44,10 +44,17 @@ void _free_r(struct _reent *r, void* ptr) {
|
||||||
return vPortFree(ptr);
|
return vPortFree(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: improve realloc to grow buffer in place if possible
|
|
||||||
void* _realloc_r(struct _reent *r, void* ptr, size_t size) {
|
void* _realloc_r(struct _reent *r, void* ptr, size_t size) {
|
||||||
void* new_chunk = pvPortMalloc(size);
|
void* new_chunk;
|
||||||
if (new_chunk) {
|
if (size == 0) {
|
||||||
|
if (ptr) {
|
||||||
|
vPortFree(ptr);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
new_chunk = pvPortMalloc(size);
|
||||||
|
if (new_chunk && ptr) {
|
||||||
memcpy(new_chunk, ptr, size);
|
memcpy(new_chunk, ptr, size);
|
||||||
vPortFree(ptr);
|
vPortFree(ptr);
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue