Merge branch '674-abort-when-memory-allocation-fails' into 'master'

Resolve "abort when memory allocation fails"

Closes #674

See merge request isc-projects/bind9!1025
This commit is contained in:
Ondřej Surý
2018-11-15 11:37:46 -05:00
3 changed files with 28 additions and 5 deletions

View File

@@ -1,3 +1,5 @@
5098. [func] Failed memory allocations are now fatal. [GL #674]
5097. [cleanup] Remove embedded ATF unit testing framework
from BIND source distribution. [GL !875]

View File

@@ -533,8 +533,6 @@ signset(dns_diff_t *del, dns_diff_t *add, dns_dbnode_t *node, dns_name_t *name,
arraysize += dns_rdataset_count(&sigset);
wassignedby = isc_mem_get(mctx, arraysize * sizeof(bool));
nowsignedby = isc_mem_get(mctx, arraysize * sizeof(bool));
if (wassignedby == NULL || nowsignedby == NULL)
fatal("out of memory");
for (i = 0; i < arraysize; i++)
wassignedby[i] = nowsignedby[i] = false;

View File

@@ -14,6 +14,7 @@
#include <config.h>
#include <inttypes.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
@@ -712,10 +713,32 @@ 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)
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];
strerror_r(errno, strbuf, sizeof(strbuf));
isc_error_fatal(__FILE__, __LINE__, "malloc failed: %s", strbuf);
}
return (ptr);
}
static void