diff options
Diffstat (limited to 'server/util.c')
-rw-r--r-- | server/util.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/server/util.c b/server/util.c index abecf23bb3..864a6b86a5 100644 --- a/server/util.c +++ b/server/util.c @@ -2583,3 +2583,36 @@ AP_DECLARE(void) ap_varbuf_free(struct ap_varbuf *vb) } vb->buf = NULL; } + +#define OOM_MESSAGE "[crit] Memory allocation failed, " \ + "aborting process." APR_EOL_STR + +AP_DECLARE(void) ap_abort_on_oom() +{ + write(STDERR_FILENO, OOM_MESSAGE, strlen(OOM_MESSAGE)); + abort(); +} + +AP_DECLARE(void *) ap_malloc(size_t size) +{ + void *p = malloc(size); + if (p == NULL && size != 0) + ap_abort_on_oom(); + return p; +} + +AP_DECLARE(void *) ap_calloc(size_t nelem, size_t size) +{ + void *p = calloc(nelem, size); + if (p == NULL && nelem != 0 && size != 0) + ap_abort_on_oom(); + return p; +} + +AP_DECLARE(void *) ap_realloc(void *ptr, size_t size) +{ + void *p = realloc(ptr, size); + if (p == NULL && size != 0) + ap_abort_on_oom(); + return p; +} |