mirror of
https://github.com/isc-projects/bind9.git
synced 2026-05-28 04:34:54 -04:00
simplified quantize(); fill memory with nonzero values if ISC_MEM_FILL==1
This commit is contained in:
parent
d5850aa99c
commit
acfa3ff9c8
1 changed files with 15 additions and 12 deletions
|
|
@ -90,24 +90,18 @@ static size_t quantize(size_t);
|
|||
|
||||
/* Private Inline-able. */
|
||||
|
||||
static inline size_t
|
||||
static inline size_t
|
||||
quantize(size_t size) {
|
||||
int remainder;
|
||||
int temp;
|
||||
|
||||
/*
|
||||
* If there is no remainder for the integer division of
|
||||
*
|
||||
* (rightsize/ALIGNMENT_SIZE)
|
||||
*
|
||||
* then we already have a good size; if not, then we need
|
||||
* to round up the result in order to get a size big
|
||||
* Round up the result in order to get a size big
|
||||
* enough to satisfy the request and be aligned on ALIGNMENT_SIZE
|
||||
* byte boundaries.
|
||||
*/
|
||||
remainder = size % ALIGNMENT_SIZE;
|
||||
if (remainder != 0)
|
||||
size += ALIGNMENT_SIZE - remainder;
|
||||
return (size);
|
||||
|
||||
temp = size + (ALIGNMENT_SIZE - 1);
|
||||
return (temp - temp % ALIGNMENT_SIZE);
|
||||
}
|
||||
|
||||
/* Public. */
|
||||
|
|
@ -330,6 +324,11 @@ __isc_mem_get(isc_mem_t *ctx, size_t size) {
|
|||
done:
|
||||
UNLOCK(&ctx->lock);
|
||||
|
||||
#if ISC_MEM_FILL
|
||||
if (ret != NULL)
|
||||
memset(ret, 0xbe, new_size); /* Mnemonic for "beef". */
|
||||
#endif
|
||||
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
|
@ -341,6 +340,10 @@ __isc_mem_put(isc_mem_t *ctx, void *mem, size_t size) {
|
|||
REQUIRE(VALID_CONTEXT(ctx));
|
||||
LOCK(&ctx->lock);
|
||||
|
||||
#if ISC_MEM_FILL
|
||||
memset(mem, 0xde, new_size); /* Mnemonic for "dead". */
|
||||
#endif
|
||||
|
||||
if (size == ctx->max_size || new_size >= ctx->max_size) {
|
||||
/* memput() called on something beyond our upper limit */
|
||||
free(mem);
|
||||
|
|
|
|||
Loading…
Reference in a new issue