[PATCH 1/6] libm/stdlib: Recover from realloc failure when shrinking
Keith Packard via Newlib <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
When shrinking and the new allocation fails, just leave things as they were and keep going. Applications may well expect shrinking reallocations to always succeed. Signed-off-by: Keith Packard <[email protected]> --- newlib/libc/stdlib/nano-mallocr.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/newlib/libc/stdlib/nano-mallocr.c b/newlib/libc/stdlib/nano-mallocr.c index 6ba0eb74b..0b032d833 100644 --- a/newlib/libc/stdlib/nano-mallocr.c +++ b/newlib/libc/stdlib/nano-mallocr.c @@ -481,7 +481,12 @@ void * nano_realloc(RARG void * ptr, malloc_size_t size) return ptr; mem = nano_malloc(RCALL size); - if (mem != NULL) + if (mem == NULL) + { + if (size <= old_size) + return ptr; + } + else { if (old_size > size) old_size = size; -- 2.28.0