2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

Remove overrun checking code from memory allocator

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.
This commit is contained in:
Ondřej Surý
2021-02-05 17:18:28 +01:00
parent 549e5b693a
commit ff47b47f1a

View 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". */
}