diff --git a/bin/sh/memalloc.c b/bin/sh/memalloc.c index 58d1be8ccd4e..a2191771386d 100644 --- a/bin/sh/memalloc.c +++ b/bin/sh/memalloc.c @@ -50,6 +50,13 @@ __FBSDID("$FreeBSD$"); #include #include +static void +badalloc(const char *message) +{ + write(2, message, strlen(message)); + abort(); +} + /* * Like malloc, but returns an error when out of space. */ @@ -59,9 +66,9 @@ ckmalloc(size_t nbytes) { pointer p; - INTOFF; + if (!is_int_on()) + badalloc("Unsafe ckmalloc() call\n"); p = malloc(nbytes); - INTON; if (p == NULL) error("Out of space"); return p; @@ -75,9 +82,9 @@ ckmalloc(size_t nbytes) pointer ckrealloc(pointer p, int nbytes) { - INTOFF; + if (!is_int_on()) + badalloc("Unsafe ckrealloc() call\n"); p = realloc(p, nbytes); - INTON; if (p == NULL) error("Out of space"); return p; @@ -86,9 +93,9 @@ ckrealloc(pointer p, int nbytes) void ckfree(pointer p) { - INTOFF; + if (!is_int_on()) + badalloc("Unsafe ckfree() call\n"); free(p); - INTON; }