]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Remove overrun checking code from memory allocator
authorOndřej Surý <ondrej@sury.org>
Fri, 5 Feb 2021 16:18:28 +0000 (17:18 +0100)
committerOndřej Surý <ondrej@sury.org>
Thu, 18 Feb 2021 18:33:54 +0000 (19:33 +0100)
The ISC_MEM_CHECKOVERRUN would add canary byte at the end of every
allocations and check whether the canary byte hasn't been changed at the
free time.  The AddressSanitizer and valgrind memory checks surpases
simple checks like this, so there's no need to actually keep the code
inside the allocator.

lib/isc/mem.c

index 103667a08794ad302eeae83393935f7de2b5c1d9..9f6db54823070222d69b53670b04d9bdc9a89170 100644 (file)
@@ -339,9 +339,6 @@ static inline void *
 mem_get(isc_mem_t *ctx, size_t size) {
        char *ret;
 
-#if ISC_MEM_CHECKOVERRUN
-       size += 1;
-#endif /* if ISC_MEM_CHECKOVERRUN */
        ret = default_memalloc(size);
 
        if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) {
@@ -349,14 +346,6 @@ mem_get(isc_mem_t *ctx, size_t size) {
                        memset(ret, 0xbe, size); /* Mnemonic for "beef". */
                }
        }
-#if ISC_MEM_CHECKOVERRUN
-       else
-       {
-               if (ISC_LIKELY(ret != NULL)) {
-                       ret[size - 1] = 0xbe;
-               }
-       }
-#endif /* if ISC_MEM_CHECKOVERRUN */
 
        return (ret);
 }
@@ -367,10 +356,6 @@ mem_get(isc_mem_t *ctx, size_t size) {
 /* coverity[+free : arg-1] */
 static inline void
 mem_put(isc_mem_t *ctx, void *mem, size_t size) {
-#if ISC_MEM_CHECKOVERRUN
-       INSIST(((unsigned char *)mem)[size] == 0xbe);
-       size += 1;
-#endif /* if ISC_MEM_CHECKOVERRUN */
        if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) {
                memset(mem, 0xde, size); /* Mnemonic for "dead". */
        }