summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2002-08-09 10:16:24 +0000
committerphk <phk@FreeBSD.org>2002-08-09 10:16:24 +0000
commit95cd15c43dc4cd1b1ecc54391e5ae427d7a8eeaf (patch)
tree9e6c76055bc8308c6d09279f18ad60408daf163a /lib
parentade75a9d08449a597f9e70f161d9e40ed722d320 (diff)
downloadFreeBSD-src-95cd15c43dc4cd1b1ecc54391e5ae427d7a8eeaf.zip
FreeBSD-src-95cd15c43dc4cd1b1ecc54391e5ae427d7a8eeaf.tar.gz
Make sure we set errno sensibly in case of failure.
Spotted by: ache
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdlib/malloc.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c
index 3bf2932..d97e872 100644
--- a/lib/libc/stdlib/malloc.c
+++ b/lib/libc/stdlib/malloc.c
@@ -1093,6 +1093,7 @@ malloc(size_t size)
wrtwarning("recursive call\n");
malloc_active--;
THREAD_UNLOCK();
+ errno = EDOFUS;
return (0);
}
if (!malloc_started)
@@ -1108,6 +1109,8 @@ malloc(size_t size)
THREAD_UNLOCK();
if (malloc_xmalloc && !r)
wrterror("out of memory\n");
+ if (!r)
+ errno = ENOMEM;
return (r);
}
@@ -1120,6 +1123,7 @@ free(void *ptr)
wrtwarning("recursive call\n");
malloc_active--;
THREAD_UNLOCK();
+ errno = EDOFUS;
return;
}
if (ptr != ZEROSIZEPTR)
@@ -1142,6 +1146,7 @@ realloc(void *ptr, size_t size)
wrtwarning("recursive call\n");
malloc_active--;
THREAD_UNLOCK();
+ errno = EDOFUS;
return (0);
}
if (ptr && !malloc_started) {
@@ -1170,6 +1175,8 @@ realloc(void *ptr, size_t size)
THREAD_UNLOCK();
if (malloc_xmalloc && err)
wrterror("out of memory\n");
+ if (err)
+ errno = ENOMEM;
return (r);
}
OpenPOWER on IntegriCloud