diff options
author | H. Peter Anvin <hpa@zytor.com> | 2001-10-23 06:01:43 +0000 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2001-10-23 06:01:43 +0000 |
commit | fbb530110cb5127532ed6ff1081f84abf574c43d (patch) | |
tree | fd8ab0a521e7b90729f9e2b28e9bdd796d32e219 /realloc.c | |
parent | d15e7744e7ab4cb7fa0ebdd8e8d652674dd95afa (diff) | |
download | lpsm-fbb530110cb5127532ed6ff1081f84abf574c43d.tar.gz lpsm-fbb530110cb5127532ed6ff1081f84abf574c43d.tar.xz lpsm-fbb530110cb5127532ed6ff1081f84abf574c43d.zip |
Be a bit more correct: set errno to ENOMEM if we fail to allocate
memory.
Diffstat (limited to 'realloc.c')
-rw-r--r-- | realloc.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -23,6 +23,7 @@ #include <inttypes.h> #include <limits.h> #include <string.h> +#include <errno.h> #include "lpsm.h" #include "internals.h" @@ -43,8 +44,10 @@ static void *lpsm_realloc_buddy(void *ptr, size_t new_size) if ( order > AH->arena_size_lg2 ) { /* Need to extend the arena immediately... */ - if ( lpsm_extend_arena(order+1) ) + if ( lpsm_extend_arena(order+1) ) { + errno = ENOMEM; return NULL; + } } rorder = AH->arena_size_lg2 - order; @@ -94,8 +97,10 @@ static void *lpsm_realloc_buddy(void *ptr, size_t new_size) /* Careful. If lpsm_malloc_buddy resizes the arena we need to adjust the rorder and xbit values afterwards. */ nptr = lpsm_malloc_buddy(new_size); - if ( !nptr ) + if ( !nptr ) { + errno = ENOMEM; return NULL; /* realloc failed */ + } memcpy(nptr, ptr, current_size); @@ -162,8 +167,10 @@ static void *lpsm_realloc_slab(void *ptr, size_t new_size) if ( new_size > si->size ) { /* This also covers the possibility of new_size > slab_max */ void *nptr = lpsm_malloc(new_size); - if ( !nptr ) + if ( !nptr ) { + errno = ENOMEM; return NULL; + } memcpy(nptr, ptr, si->size); lpsm_free_slab(ptr); return nptr; |