2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 22:15:20 +00:00

Merge branch '3845-mem-zero-non-zero' into 'main'

Fix ISC_MEM_ZERO on allocators with malloc_usable_size()

Closes #3845

See merge request isc-projects/bind9!7481
This commit is contained in:
Tony Finch
2023-02-06 12:09:28 +00:00
2 changed files with 11 additions and 4 deletions

View File

@@ -1,3 +1,6 @@
6084. [bug] When BIND was built without jemalloc, the allocator flag
ISC_MEM_ZERO could return non-zero memory. [GL #3845]
6083. [bug] Fix DNSRPS-enabled builds as they were inadvertently
broken by changes 5949 and 6042. [GL #3827]

View File

@@ -66,7 +66,7 @@ mallocx(size_t size, int flags) {
INSIST(ptr != NULL);
if ((flags & MALLOCX_ZERO) != 0) {
memset(ptr, 0, size);
memset(ptr, 0, sallocx(ptr, flags));
}
return (ptr);
@@ -83,7 +83,7 @@ sdallocx(void *ptr, size_t size, int flags) {
static inline void *
rallocx(void *ptr, size_t size, int flags) {
void *new_ptr;
size_t old_size;
size_t old_size, new_size;
REQUIRE(size != 0);
@@ -94,8 +94,12 @@ rallocx(void *ptr, size_t size, int flags) {
new_ptr = realloc(ptr, size);
INSIST(new_ptr != NULL);
if ((flags & MALLOCX_ZERO) != 0 && size > old_size) {
memset((uint8_t *)new_ptr + old_size, 0, size - old_size);
if ((flags & MALLOCX_ZERO) != 0) {
new_size = sallocx(new_ptr, flags);
if (new_size > old_size) {
memset((uint8_t *)new_ptr + old_size, 0,
new_size - old_size);
}
}
return (new_ptr);