kopia lustrzana https://github.com/espressif/esp-idf
Merge branch 'bugfix/realloc' into 'master'
modify realloc behaves modify realloc behaves just like malloc when pass a null pointer for ptr. See merge request !66pull/21/head
commit
fe3380d32e
|
@ -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