]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Abort on allocation failure only if the memory functions are used internally in BIND 9
authorOndřej Surý <ondrej@sury.org>
Thu, 20 Dec 2018 10:20:10 +0000 (11:20 +0100)
committerOndřej Surý <ondrej@isc.org>
Fri, 21 Dec 2018 08:03:24 +0000 (03:03 -0500)
(cherry picked from commit c22241ae9009391c1d28085c5cf0009a6caef09c)

lib/isc/mem.c

index 1f73805f6d81f4bf7c80604160168bd8ff5a0550..49b61c994caef9c5d7bab13fe8d47168f704e4ba 100644 (file)
@@ -862,6 +862,17 @@ mem_putstats(isc__mem_t *ctx, void *ptr, size_t size) {
 
 static void *
 default_memalloc(void *arg, size_t size) {
+       UNUSED(arg);
+
+       if (size == 0U) {
+               size = 1;
+       }
+
+       return (malloc(size));
+}
+
+static void *
+internal_memalloc(void *arg, size_t size) {
        void *ptr;
        UNUSED(arg);
 
@@ -2735,7 +2746,7 @@ isc_mem_create(size_t init_max_size, size_t target_size, isc_mem_t **mctxp) {
 
        if (isc_bind9)
                return (isc_mem_createx2(init_max_size, target_size,
-                                        default_memalloc, default_memfree,
+                                        internal_memalloc, default_memfree,
                                         NULL, mctxp, isc_mem_defaultflags));
        LOCK(&createlock);
 
@@ -2754,7 +2765,7 @@ isc_mem_create2(size_t init_max_size, size_t target_size, isc_mem_t **mctxp,
 {
        if (isc_bind9)
                return (isc_mem_createx2(init_max_size, target_size,
-                                        default_memalloc, default_memfree,
+                                        internal_memalloc, default_memfree,
                                         NULL, mctxp, flags));
 
        return (isc_mem_createx2(init_max_size, target_size,