aboutsummaryrefslogtreecommitdiffstats
path: root/realloc.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2001-10-23 06:01:43 +0000
committerH. Peter Anvin <hpa@zytor.com>2001-10-23 06:01:43 +0000
commitfbb530110cb5127532ed6ff1081f84abf574c43d (patch)
treefd8ab0a521e7b90729f9e2b28e9bdd796d32e219 /realloc.c
parentd15e7744e7ab4cb7fa0ebdd8e8d652674dd95afa (diff)
downloadlpsm-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.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/realloc.c b/realloc.c
index 3dce36e..27b2f1e 100644
--- a/realloc.c
+++ b/realloc.c
@@ -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;