Commit 1543df6b authored by Ondřej Surý's avatar Ondřej Surý
Browse files

Abort on memory allocation failure

(cherry picked from commit 8de24517)
parent 5ebd68b5
......@@ -14,6 +14,7 @@
#include <config.h>
#include <inttypes.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -29,6 +30,7 @@
#include <isc/once.h>
#include <isc/ondestroy.h>
#include <isc/string.h>
#include <isc/strerror.h>
#include <isc/mutex.h>
#include <isc/print.h>
#include <isc/util.h>
......@@ -844,10 +846,36 @@ mem_putstats(isc__mem_t *ctx, void *ptr, size_t size) {
static void *
default_memalloc(void *arg, size_t size) {
void *ptr;
UNUSED(arg);
if (size == 0U)
if (size == 0U) {
size = 1;
return (malloc(size));
}
ptr = malloc(size);
/*
* If the space cannot be allocated, a null pointer is returned. If the
* size of the space requested is zero, the behavior is
* implementation-defined: either a null pointer is returned, or the
* behavior is as if the size were some nonzero value, except that the
* returned pointer shall not be used to access an object.
* [ISO9899 § 7.22.3]
*
* [ISO9899]
* ISO/IEC WG 9899:2011: Programming languages - C.
* International Organization for Standardization, Geneva, Switzerland.
* http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1570.pdf
*/
if (ptr == NULL && size != 0) {
char strbuf[ISC_STRERRORSIZE];
isc__strerror(errno, strbuf, sizeof(strbuf));
isc_error_fatal(__FILE__, __LINE__, "malloc failed: %s", strbuf);
}
return (ptr);
}
static void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment