mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
Use clang-tidy to add curly braces around one-line statements
The command used to reformat the files in this commit was: ./util/run-clang-tidy \ -clang-tidy-binary clang-tidy-11 -clang-apply-replacements-binary clang-apply-replacements-11 \ -checks=-*,readability-braces-around-statements \ -j 9 \ -fix \ -format \ -style=file \ -quiet clang-format -i --style=format $(git ls-files '*.c' '*.h') uncrustify -c .uncrustify.cfg --replace --no-backup $(git ls-files '*.c' '*.h') clang-format -i --style=format $(git ls-files '*.c' '*.h')
This commit is contained in:
280
lib/isc/mem.c
280
lib/isc/mem.c
@@ -47,7 +47,7 @@
|
||||
|
||||
#ifndef ISC_MEM_DEBUGGING
|
||||
#define ISC_MEM_DEBUGGING 0
|
||||
#endif
|
||||
#endif /* ifndef ISC_MEM_DEBUGGING */
|
||||
LIBISC_EXTERNAL_DATA unsigned int isc_mem_debugging = ISC_MEM_DEBUGGING;
|
||||
LIBISC_EXTERNAL_DATA unsigned int isc_mem_defaultflags = ISC_MEMFLAG_DEFAULT;
|
||||
|
||||
@@ -82,10 +82,10 @@ typedef ISC_LIST(debuglink_t) debuglist_t;
|
||||
|
||||
#define FLARG_PASS , file, line
|
||||
#define FLARG , const char *file, unsigned int line
|
||||
#else
|
||||
#else /* if ISC_MEM_TRACKLINES */
|
||||
#define FLARG_PASS
|
||||
#define FLARG
|
||||
#endif
|
||||
#endif /* if ISC_MEM_TRACKLINES */
|
||||
|
||||
typedef struct element element;
|
||||
struct element {
|
||||
@@ -173,7 +173,7 @@ struct isc__mem {
|
||||
#if ISC_MEM_TRACKLINES
|
||||
debuglist_t *debuglist;
|
||||
size_t debuglistcnt;
|
||||
#endif
|
||||
#endif /* if ISC_MEM_TRACKLINES */
|
||||
|
||||
ISC_LINK(isc__mem_t) link;
|
||||
};
|
||||
@@ -201,7 +201,7 @@ struct isc__mempool {
|
||||
/*%< Debugging only. */
|
||||
#if ISC_MEMPOOL_NAMES
|
||||
char name[16]; /*%< printed name in stats reports */
|
||||
#endif
|
||||
#endif /* if ISC_MEMPOOL_NAMES */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -212,7 +212,7 @@ struct isc__mempool {
|
||||
#define ADD_TRACE(a, b, c, d, e)
|
||||
#define DELETE_TRACE(a, b, c, d, e)
|
||||
#define ISC_MEMFUNC_SCOPE
|
||||
#else
|
||||
#else /* if !ISC_MEM_TRACKLINES */
|
||||
#define TRACE_OR_RECORD (ISC_MEM_DEBUGTRACE | ISC_MEM_DEBUGRECORD)
|
||||
#define ADD_TRACE(a, b, c, d, e) \
|
||||
do { \
|
||||
@@ -269,8 +269,9 @@ add_trace_entry(isc__mem_t *mctx, const void *ptr, size_t size FLARG)
|
||||
ptr, size, file, line, mctx);
|
||||
}
|
||||
|
||||
if (mctx->debuglist == NULL)
|
||||
if (mctx->debuglist == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
hash = isc_hash_function(&ptr, sizeof(ptr), true);
|
||||
idx = hash % DEBUG_TABLE_COUNT;
|
||||
@@ -278,8 +279,9 @@ add_trace_entry(isc__mem_t *mctx, const void *ptr, size_t size FLARG)
|
||||
dl = malloc(sizeof(debuglink_t));
|
||||
INSIST(dl != NULL);
|
||||
mctx->malloced += sizeof(debuglink_t);
|
||||
if (mctx->malloced > mctx->maxmalloced)
|
||||
if (mctx->malloced > mctx->maxmalloced) {
|
||||
mctx->maxmalloced = mctx->malloced;
|
||||
}
|
||||
|
||||
ISC_LINK_INIT(dl, link);
|
||||
dl->ptr = ptr;
|
||||
@@ -304,8 +306,9 @@ delete_trace_entry(isc__mem_t *mctx, const void *ptr, size_t size,
|
||||
ptr, size, file, line, mctx);
|
||||
}
|
||||
|
||||
if (mctx->debuglist == NULL)
|
||||
if (mctx->debuglist == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
hash = isc_hash_function(&ptr, sizeof(ptr), true);
|
||||
idx = hash % DEBUG_TABLE_COUNT;
|
||||
@@ -348,8 +351,9 @@ quantize(size_t size)
|
||||
* byte boundaries.
|
||||
*/
|
||||
|
||||
if (size == 0U)
|
||||
if (size == 0U) {
|
||||
return (ALIGNMENT_SIZE);
|
||||
}
|
||||
return ((size + ALIGNMENT_SIZE - 1) & (~(ALIGNMENT_SIZE - 1)));
|
||||
}
|
||||
|
||||
@@ -369,8 +373,9 @@ more_basic_blocks(isc__mem_t *ctx)
|
||||
table_size = ctx->basic_table_size + TABLE_INCREMENT;
|
||||
table = (ctx->memalloc)(table_size * sizeof(unsigned char *));
|
||||
ctx->malloced += table_size * sizeof(unsigned char *);
|
||||
if (ctx->malloced > ctx->maxmalloced)
|
||||
if (ctx->malloced > ctx->maxmalloced) {
|
||||
ctx->maxmalloced = ctx->malloced;
|
||||
}
|
||||
if (ctx->basic_table_size != 0) {
|
||||
memmove(table, ctx->basic_table,
|
||||
ctx->basic_table_size *
|
||||
@@ -385,7 +390,6 @@ more_basic_blocks(isc__mem_t *ctx)
|
||||
|
||||
tmp = (ctx->memalloc)(NUM_BASIC_BLOCKS * ctx->mem_target);
|
||||
ctx->total += NUM_BASIC_BLOCKS * ctx->mem_target;
|
||||
;
|
||||
ctx->basic_table[ctx->basic_table_count] = tmp;
|
||||
ctx->basic_table_count++;
|
||||
ctx->malloced += NUM_BASIC_BLOCKS * ctx->mem_target;
|
||||
@@ -484,8 +488,9 @@ mem_getunlocked(isc__mem_t *ctx, size_t size)
|
||||
ctx->stats[ctx->max_size].gets++;
|
||||
ctx->stats[ctx->max_size].totalgets++;
|
||||
ctx->malloced += size;
|
||||
if (ctx->malloced > ctx->maxmalloced)
|
||||
if (ctx->malloced > ctx->maxmalloced) {
|
||||
ctx->maxmalloced = ctx->malloced;
|
||||
}
|
||||
/*
|
||||
* If we don't set new_size to size, then the
|
||||
* ISC_MEMFLAG_FILL code might write over bytes we don't
|
||||
@@ -523,8 +528,9 @@ mem_getunlocked(isc__mem_t *ctx, size_t size)
|
||||
|
||||
done:
|
||||
if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0) &&
|
||||
ISC_LIKELY(ret != NULL))
|
||||
ISC_LIKELY(ret != NULL)) {
|
||||
memset(ret, 0xbe, new_size); /* Mnemonic for "beef". */
|
||||
}
|
||||
|
||||
return (ret);
|
||||
}
|
||||
@@ -543,7 +549,7 @@ check_overrun(void *mem, size_t size, size_t new_size)
|
||||
size++;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* if ISC_MEM_CHECKOVERRUN */
|
||||
|
||||
/* coverity[+free : arg-1] */
|
||||
static inline void
|
||||
@@ -555,8 +561,9 @@ mem_putunlocked(isc__mem_t *ctx, void *mem, size_t size)
|
||||
/*
|
||||
* memput() called on something beyond our upper limit.
|
||||
*/
|
||||
if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0))
|
||||
if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) {
|
||||
memset(mem, 0xde, size); /* Mnemonic for "dead". */
|
||||
}
|
||||
|
||||
(ctx->memfree)(mem);
|
||||
INSIST(ctx->stats[ctx->max_size].gets != 0U);
|
||||
@@ -570,7 +577,7 @@ mem_putunlocked(isc__mem_t *ctx, void *mem, size_t size)
|
||||
if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) {
|
||||
#if ISC_MEM_CHECKOVERRUN
|
||||
check_overrun(mem, size, new_size);
|
||||
#endif
|
||||
#endif /* if ISC_MEM_CHECKOVERRUN */
|
||||
memset(mem, 0xde, new_size); /* Mnemonic for "dead". */
|
||||
}
|
||||
|
||||
@@ -602,19 +609,21 @@ mem_get(isc__mem_t *ctx, size_t size)
|
||||
|
||||
#if ISC_MEM_CHECKOVERRUN
|
||||
size += 1;
|
||||
#endif
|
||||
#endif /* if ISC_MEM_CHECKOVERRUN */
|
||||
ret = (ctx->memalloc)(size);
|
||||
|
||||
if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) {
|
||||
if (ISC_LIKELY(ret != NULL))
|
||||
if (ISC_LIKELY(ret != NULL)) {
|
||||
memset(ret, 0xbe, size); /* Mnemonic for "beef". */
|
||||
}
|
||||
}
|
||||
#if ISC_MEM_CHECKOVERRUN
|
||||
else {
|
||||
if (ISC_LIKELY(ret != NULL))
|
||||
if (ISC_LIKELY(ret != NULL)) {
|
||||
ret[size - 1] = 0xbe;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* if ISC_MEM_CHECKOVERRUN */
|
||||
|
||||
return (ret);
|
||||
}
|
||||
@@ -629,9 +638,10 @@ 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_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0))
|
||||
#endif /* if ISC_MEM_CHECKOVERRUN */
|
||||
if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) {
|
||||
memset(mem, 0xde, size); /* Mnemonic for "dead". */
|
||||
}
|
||||
(ctx->memfree)(mem);
|
||||
}
|
||||
|
||||
@@ -654,10 +664,11 @@ mem_getstats(isc__mem_t *ctx, size_t size)
|
||||
|
||||
#if ISC_MEM_CHECKOVERRUN
|
||||
size += 1;
|
||||
#endif
|
||||
#endif /* if ISC_MEM_CHECKOVERRUN */
|
||||
ctx->malloced += size;
|
||||
if (ctx->malloced > ctx->maxmalloced)
|
||||
if (ctx->malloced > ctx->maxmalloced) {
|
||||
ctx->maxmalloced = ctx->malloced;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -680,7 +691,7 @@ mem_putstats(isc__mem_t *ctx, void *ptr, size_t size)
|
||||
}
|
||||
#if ISC_MEM_CHECKOVERRUN
|
||||
size += 1;
|
||||
#endif
|
||||
#endif /* if ISC_MEM_CHECKOVERRUN */
|
||||
ctx->malloced -= size;
|
||||
}
|
||||
|
||||
@@ -777,7 +788,7 @@ mem_create(isc_mem_t **ctxp, unsigned int flags)
|
||||
#if ISC_MEM_TRACKLINES
|
||||
ctx->debuglist = NULL;
|
||||
ctx->debuglistcnt = 0;
|
||||
#endif
|
||||
#endif /* if ISC_MEM_TRACKLINES */
|
||||
ISC_LIST_INIT(ctx->pools);
|
||||
ctx->poolcnt = 0;
|
||||
ctx->freelists = NULL;
|
||||
@@ -810,12 +821,13 @@ mem_create(isc_mem_t **ctxp, unsigned int flags)
|
||||
|
||||
ctx->debuglist = (ctx->memalloc)(
|
||||
(DEBUG_TABLE_COUNT * sizeof(debuglist_t)));
|
||||
for (i = 0; i < DEBUG_TABLE_COUNT; i++)
|
||||
for (i = 0; i < DEBUG_TABLE_COUNT; i++) {
|
||||
ISC_LIST_INIT(ctx->debuglist[i]);
|
||||
}
|
||||
ctx->malloced += DEBUG_TABLE_COUNT * sizeof(debuglist_t);
|
||||
ctx->maxmalloced += DEBUG_TABLE_COUNT * sizeof(debuglist_t);
|
||||
}
|
||||
#endif
|
||||
#endif /* if ISC_MEM_TRACKLINES */
|
||||
|
||||
LOCK(&contextslock);
|
||||
ISC_LIST_INITANDAPPEND(contexts, ctx, link);
|
||||
@@ -846,22 +858,24 @@ destroy(isc__mem_t *ctx)
|
||||
#if ISC_MEM_TRACKLINES
|
||||
if (ISC_UNLIKELY(ctx->debuglist != NULL)) {
|
||||
debuglink_t *dl;
|
||||
for (i = 0; i < DEBUG_TABLE_COUNT; i++)
|
||||
for (i = 0; i < DEBUG_TABLE_COUNT; i++) {
|
||||
for (dl = ISC_LIST_HEAD(ctx->debuglist[i]); dl != NULL;
|
||||
dl = ISC_LIST_HEAD(ctx->debuglist[i])) {
|
||||
if (ctx->checkfree && dl->ptr != NULL)
|
||||
if (ctx->checkfree && dl->ptr != NULL) {
|
||||
print_active(ctx, stderr);
|
||||
}
|
||||
INSIST(!ctx->checkfree || dl->ptr == NULL);
|
||||
|
||||
ISC_LIST_UNLINK(ctx->debuglist[i], dl, link);
|
||||
free(dl);
|
||||
ctx->malloced -= sizeof(*dl);
|
||||
}
|
||||
}
|
||||
|
||||
(ctx->memfree)(ctx->debuglist);
|
||||
ctx->malloced -= DEBUG_TABLE_COUNT * sizeof(debuglist_t);
|
||||
}
|
||||
#endif
|
||||
#endif /* if ISC_MEM_TRACKLINES */
|
||||
|
||||
if (ctx->checkfree) {
|
||||
for (i = 0; i <= ctx->max_size; i++) {
|
||||
@@ -873,7 +887,7 @@ destroy(isc__mem_t *ctx)
|
||||
ctx, ctx->name, i, ctx->stats[i].gets);
|
||||
#if ISC_MEM_TRACKLINES
|
||||
print_active(ctx, stderr);
|
||||
#endif
|
||||
#endif /* if ISC_MEM_TRACKLINES */
|
||||
INSIST(ctx->stats[i].gets == 0U);
|
||||
}
|
||||
}
|
||||
@@ -899,8 +913,9 @@ destroy(isc__mem_t *ctx)
|
||||
isc_mutex_destroy(&ctx->lock);
|
||||
|
||||
ctx->malloced -= sizeof(*ctx);
|
||||
if (ctx->checkfree)
|
||||
if (ctx->checkfree) {
|
||||
INSIST(ctx->malloced == 0);
|
||||
}
|
||||
(ctx->memfree)(ctx);
|
||||
}
|
||||
|
||||
@@ -955,8 +970,9 @@ isc___mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG)
|
||||
if ((isc_mem_debugging & ISC_MEM_DEBUGSIZE) != 0) {
|
||||
size_info *si = &(((size_info *)ptr)[-1]);
|
||||
size_t oldsize = si->u.size - ALIGNMENT_SIZE;
|
||||
if ((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0)
|
||||
if ((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0) {
|
||||
oldsize -= ALIGNMENT_SIZE;
|
||||
}
|
||||
INSIST(oldsize == size);
|
||||
}
|
||||
isc__mem_free((isc_mem_t *)ctx, ptr FLARG_PASS);
|
||||
@@ -999,9 +1015,9 @@ isc_mem_destroy(isc_mem_t **ctxp)
|
||||
if (isc_refcount_decrement(&ctx->references) > 1) {
|
||||
print_active(ctx, stderr);
|
||||
}
|
||||
#else
|
||||
#else /* if ISC_MEM_TRACKLINES */
|
||||
isc_refcount_decrement(&ctx->references);
|
||||
#endif
|
||||
#endif /* if ISC_MEM_TRACKLINES */
|
||||
isc_refcount_destroy(&ctx->references);
|
||||
destroy(ctx);
|
||||
|
||||
@@ -1018,8 +1034,9 @@ isc___mem_get(isc_mem_t *ctx0, size_t size FLARG)
|
||||
bool call_water = false;
|
||||
|
||||
if (ISC_UNLIKELY((isc_mem_debugging &
|
||||
(ISC_MEM_DEBUGSIZE | ISC_MEM_DEBUGCTX)) != 0))
|
||||
(ISC_MEM_DEBUGSIZE | ISC_MEM_DEBUGCTX)) != 0)) {
|
||||
return (isc__mem_allocate(ctx0, size FLARG_PASS));
|
||||
}
|
||||
|
||||
if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
|
||||
MCTXLOCK(ctx);
|
||||
@@ -1027,28 +1044,32 @@ isc___mem_get(isc_mem_t *ctx0, size_t size FLARG)
|
||||
} else {
|
||||
ptr = mem_get(ctx, size);
|
||||
MCTXLOCK(ctx);
|
||||
if (ptr != NULL)
|
||||
if (ptr != NULL) {
|
||||
mem_getstats(ctx, size);
|
||||
}
|
||||
}
|
||||
|
||||
ADD_TRACE(ctx, ptr, size, file, line);
|
||||
|
||||
if (ctx->hi_water != 0U && ctx->inuse > ctx->hi_water) {
|
||||
ctx->is_overmem = true;
|
||||
if (!ctx->hi_called)
|
||||
if (!ctx->hi_called) {
|
||||
call_water = true;
|
||||
}
|
||||
}
|
||||
if (ctx->inuse > ctx->maxinuse) {
|
||||
ctx->maxinuse = ctx->inuse;
|
||||
if (ctx->hi_water != 0U && ctx->inuse > ctx->hi_water &&
|
||||
(isc_mem_debugging & ISC_MEM_DEBUGUSAGE) != 0)
|
||||
(isc_mem_debugging & ISC_MEM_DEBUGUSAGE) != 0) {
|
||||
fprintf(stderr, "maxinuse = %lu\n",
|
||||
(unsigned long)ctx->inuse);
|
||||
}
|
||||
}
|
||||
MCTXUNLOCK(ctx);
|
||||
|
||||
if (call_water && (ctx->water != NULL))
|
||||
if (call_water && (ctx->water != NULL)) {
|
||||
(ctx->water)(ctx->water_arg, ISC_MEM_HIWATER);
|
||||
}
|
||||
|
||||
return (ptr);
|
||||
}
|
||||
@@ -1069,8 +1090,9 @@ isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG)
|
||||
if ((isc_mem_debugging & ISC_MEM_DEBUGSIZE) != 0) {
|
||||
si = &(((size_info *)ptr)[-1]);
|
||||
oldsize = si->u.size - ALIGNMENT_SIZE;
|
||||
if ((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0)
|
||||
if ((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0) {
|
||||
oldsize -= ALIGNMENT_SIZE;
|
||||
}
|
||||
INSIST(oldsize == size);
|
||||
}
|
||||
isc__mem_free((isc_mem_t *)ctx, ptr FLARG_PASS);
|
||||
@@ -1095,14 +1117,16 @@ isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG)
|
||||
*/
|
||||
if ((ctx->inuse < ctx->lo_water) || (ctx->lo_water == 0U)) {
|
||||
ctx->is_overmem = false;
|
||||
if (ctx->hi_called)
|
||||
if (ctx->hi_called) {
|
||||
call_water = true;
|
||||
}
|
||||
}
|
||||
|
||||
MCTXUNLOCK(ctx);
|
||||
|
||||
if (call_water && (ctx->water != NULL))
|
||||
if (call_water && (ctx->water != NULL)) {
|
||||
(ctx->water)(ctx->water_arg, ISC_MEM_LOWATER);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1113,10 +1137,11 @@ isc_mem_waterack(isc_mem_t *ctx0, int flag)
|
||||
isc__mem_t *ctx = (isc__mem_t *)ctx0;
|
||||
|
||||
MCTXLOCK(ctx);
|
||||
if (flag == ISC_MEM_LOWATER)
|
||||
if (flag == ISC_MEM_LOWATER) {
|
||||
ctx->hi_called = false;
|
||||
else if (flag == ISC_MEM_HIWATER)
|
||||
} else if (flag == ISC_MEM_HIWATER) {
|
||||
ctx->hi_called = true;
|
||||
}
|
||||
MCTXUNLOCK(ctx);
|
||||
}
|
||||
|
||||
@@ -1155,7 +1180,7 @@ print_active(isc__mem_t *mctx, FILE *out)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* if ISC_MEM_TRACKLINES */
|
||||
|
||||
/*
|
||||
* Print the stats[] on the stream "out" with suitable formatting.
|
||||
@@ -1175,15 +1200,17 @@ isc_mem_stats(isc_mem_t *ctx0, FILE *out)
|
||||
for (i = 0; i <= ctx->max_size; i++) {
|
||||
s = &ctx->stats[i];
|
||||
|
||||
if (s->totalgets == 0U && s->gets == 0U)
|
||||
if (s->totalgets == 0U && s->gets == 0U) {
|
||||
continue;
|
||||
}
|
||||
fprintf(out, "%s%5lu: %11lu gets, %11lu rem",
|
||||
(i == ctx->max_size) ? ">=" : " ", (unsigned long)i,
|
||||
s->totalgets, s->gets);
|
||||
if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0 &&
|
||||
(s->blocks != 0U || s->freefrags != 0U))
|
||||
(s->blocks != 0U || s->freefrags != 0U)) {
|
||||
fprintf(out, " (%lu bl, %lu ff)", s->blocks,
|
||||
s->freefrags);
|
||||
}
|
||||
fputc('\n', out);
|
||||
}
|
||||
|
||||
@@ -1205,9 +1232,9 @@ isc_mem_stats(isc_mem_t *ctx0, FILE *out)
|
||||
fprintf(out, "%15s %10lu %10u %10u %10u %10u %10u %10u %s\n",
|
||||
#if ISC_MEMPOOL_NAMES
|
||||
pool->name,
|
||||
#else
|
||||
#else /* if ISC_MEMPOOL_NAMES */
|
||||
"(not tracked)",
|
||||
#endif
|
||||
#endif /* if ISC_MEMPOOL_NAMES */
|
||||
(unsigned long)pool->size, pool->maxalloc,
|
||||
pool->allocated, pool->freecount, pool->freemax,
|
||||
pool->fillcount, pool->gets,
|
||||
@@ -1217,7 +1244,7 @@ isc_mem_stats(isc_mem_t *ctx0, FILE *out)
|
||||
|
||||
#if ISC_MEM_TRACKLINES
|
||||
print_active(ctx, out);
|
||||
#endif
|
||||
#endif /* if ISC_MEM_TRACKLINES */
|
||||
|
||||
MCTXUNLOCK(ctx);
|
||||
}
|
||||
@@ -1234,8 +1261,9 @@ mem_allocateunlocked(isc_mem_t *ctx0, size_t size)
|
||||
size_info * si;
|
||||
|
||||
size += ALIGNMENT_SIZE;
|
||||
if (ISC_UNLIKELY((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0))
|
||||
if (ISC_UNLIKELY((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0)) {
|
||||
size += ALIGNMENT_SIZE;
|
||||
}
|
||||
|
||||
if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
|
||||
si = mem_getunlocked(ctx, size);
|
||||
@@ -1279,11 +1307,12 @@ isc___mem_allocate(isc_mem_t *ctx0, size_t size FLARG)
|
||||
}
|
||||
if (ctx->inuse > ctx->maxinuse) {
|
||||
ctx->maxinuse = ctx->inuse;
|
||||
if (ISC_UNLIKELY(ctx->hi_water != 0U &&
|
||||
ctx->inuse > ctx->hi_water &&
|
||||
(isc_mem_debugging & ISC_MEM_DEBUGUSAGE) != 0))
|
||||
if (ISC_UNLIKELY(
|
||||
ctx->hi_water != 0U && ctx->inuse > ctx->hi_water &&
|
||||
(isc_mem_debugging & ISC_MEM_DEBUGUSAGE) != 0)) {
|
||||
fprintf(stderr, "maxinuse = %lu\n",
|
||||
(unsigned long)ctx->inuse);
|
||||
}
|
||||
}
|
||||
MCTXUNLOCK(ctx);
|
||||
|
||||
@@ -1328,8 +1357,9 @@ isc___mem_reallocate(isc_mem_t *ctx0, void *ptr, size_t size FLARG)
|
||||
memmove(new_ptr, ptr, copysize);
|
||||
isc__mem_free(ctx0, ptr FLARG_PASS);
|
||||
}
|
||||
} else if (ptr != NULL)
|
||||
} else if (ptr != NULL) {
|
||||
isc__mem_free(ctx0, ptr FLARG_PASS);
|
||||
}
|
||||
|
||||
return (new_ptr);
|
||||
}
|
||||
@@ -1379,13 +1409,15 @@ isc___mem_free(isc_mem_t *ctx0, void *ptr FLARG)
|
||||
(ctx->inuse < ctx->lo_water || ctx->lo_water == 0U)) {
|
||||
ctx->hi_called = false;
|
||||
|
||||
if (ctx->water != NULL)
|
||||
if (ctx->water != NULL) {
|
||||
call_water = true;
|
||||
}
|
||||
}
|
||||
MCTXUNLOCK(ctx);
|
||||
|
||||
if (call_water)
|
||||
if (call_water) {
|
||||
(ctx->water)(ctx->water_arg, ISC_MEM_LOWATER);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1406,8 +1438,9 @@ isc___mem_strdup(isc_mem_t *mctx0, const char *s FLARG)
|
||||
|
||||
ns = isc__mem_allocate((isc_mem_t *)mctx, len FLARG_PASS);
|
||||
|
||||
if (ns != NULL)
|
||||
if (ns != NULL) {
|
||||
strlcpy(ns, s, len);
|
||||
}
|
||||
|
||||
return (ns);
|
||||
}
|
||||
@@ -1501,8 +1534,9 @@ isc_mem_setwater(isc_mem_t *ctx0, isc_mem_water_t water, void *water_arg,
|
||||
} else {
|
||||
if (ctx->hi_called &&
|
||||
(ctx->water != water || ctx->water_arg != water_arg ||
|
||||
ctx->inuse < lowater || lowater == 0U))
|
||||
ctx->inuse < lowater || lowater == 0U)) {
|
||||
callwater = true;
|
||||
}
|
||||
ctx->water = water;
|
||||
ctx->water_arg = water_arg;
|
||||
ctx->hi_water = hiwater;
|
||||
@@ -1510,8 +1544,9 @@ isc_mem_setwater(isc_mem_t *ctx0, isc_mem_water_t water, void *water_arg,
|
||||
}
|
||||
MCTXUNLOCK(ctx);
|
||||
|
||||
if (callwater && oldwater != NULL)
|
||||
if (callwater && oldwater != NULL) {
|
||||
(oldwater)(oldwater_arg, ISC_MEM_LOWATER);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -1549,8 +1584,9 @@ isc_mem_getname(isc_mem_t *ctx0)
|
||||
|
||||
isc__mem_t *ctx = (isc__mem_t *)ctx0;
|
||||
|
||||
if (ctx->name[0] == 0)
|
||||
if (ctx->name[0] == 0) {
|
||||
return ("");
|
||||
}
|
||||
|
||||
return (ctx->name);
|
||||
}
|
||||
@@ -1604,7 +1640,7 @@ isc_mempool_create(isc_mem_t *mctx0, size_t size, isc_mempool_t **mpctxp)
|
||||
mpctx->gets = 0;
|
||||
#if ISC_MEMPOOL_NAMES
|
||||
mpctx->name[0] = 0;
|
||||
#endif
|
||||
#endif /* if ISC_MEMPOOL_NAMES */
|
||||
mpctx->items = NULL;
|
||||
|
||||
*mpctxp = (isc_mempool_t *)mpctx;
|
||||
@@ -1624,17 +1660,19 @@ isc_mempool_setname(isc_mempool_t *mpctx0, const char *name)
|
||||
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
|
||||
|
||||
#if ISC_MEMPOOL_NAMES
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
LOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
strlcpy(mpctx->name, name, sizeof(mpctx->name));
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
UNLOCK(mpctx->lock);
|
||||
#else
|
||||
}
|
||||
#else /* if ISC_MEMPOOL_NAMES */
|
||||
UNUSED(mpctx);
|
||||
UNUSED(name);
|
||||
#endif
|
||||
#endif /* if ISC_MEMPOOL_NAMES */
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1650,20 +1688,22 @@ isc_mempool_destroy(isc_mempool_t **mpctxp)
|
||||
|
||||
mpctx = (isc__mempool_t *)*mpctxp;
|
||||
#if ISC_MEMPOOL_NAMES
|
||||
if (mpctx->allocated > 0)
|
||||
if (mpctx->allocated > 0) {
|
||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||
"isc_mempool_destroy(): mempool %s "
|
||||
"leaked memory",
|
||||
mpctx->name);
|
||||
#endif
|
||||
}
|
||||
#endif /* if ISC_MEMPOOL_NAMES */
|
||||
REQUIRE(mpctx->allocated == 0);
|
||||
|
||||
mctx = mpctx->mctx;
|
||||
|
||||
lock = mpctx->lock;
|
||||
|
||||
if (lock != NULL)
|
||||
if (lock != NULL) {
|
||||
LOCK(lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return any items on the free list
|
||||
@@ -1697,8 +1737,9 @@ isc_mempool_destroy(isc_mempool_t **mpctxp)
|
||||
|
||||
isc_mem_put((isc_mem_t *)mpctx->mctx, mpctx, sizeof(isc__mempool_t));
|
||||
|
||||
if (lock != NULL)
|
||||
if (lock != NULL) {
|
||||
UNLOCK(lock);
|
||||
}
|
||||
|
||||
*mpctxp = NULL;
|
||||
}
|
||||
@@ -1728,8 +1769,9 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG)
|
||||
|
||||
mctx = mpctx->mctx;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
LOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't let the caller go over quota
|
||||
@@ -1750,11 +1792,13 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG)
|
||||
item = mem_getunlocked(mctx, mpctx->size);
|
||||
} else {
|
||||
item = mem_get(mctx, mpctx->size);
|
||||
if (item != NULL)
|
||||
if (item != NULL) {
|
||||
mem_getstats(mctx, mpctx->size);
|
||||
}
|
||||
}
|
||||
if (ISC_UNLIKELY(item == NULL))
|
||||
if (ISC_UNLIKELY(item == NULL)) {
|
||||
break;
|
||||
}
|
||||
item->next = mpctx->items;
|
||||
mpctx->items = item;
|
||||
mpctx->freecount++;
|
||||
@@ -1766,8 +1810,9 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG)
|
||||
* If we didn't get any items, return NULL.
|
||||
*/
|
||||
item = mpctx->items;
|
||||
if (ISC_UNLIKELY(item == NULL))
|
||||
if (ISC_UNLIKELY(item == NULL)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
mpctx->items = item->next;
|
||||
INSIST(mpctx->freecount > 0);
|
||||
@@ -1776,8 +1821,9 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG)
|
||||
mpctx->allocated++;
|
||||
|
||||
out:
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
UNLOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
#if ISC_MEM_TRACKLINES
|
||||
if (ISC_UNLIKELY(((isc_mem_debugging & TRACE_OR_RECORD) != 0) &&
|
||||
@@ -1802,8 +1848,9 @@ isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG)
|
||||
isc__mem_t * mctx = mpctx->mctx;
|
||||
element * item;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
LOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
INSIST(mpctx->allocated > 0);
|
||||
mpctx->allocated--;
|
||||
@@ -1828,8 +1875,9 @@ isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG)
|
||||
mem_put(mctx, mem, mpctx->size);
|
||||
}
|
||||
MCTXUNLOCK(mctx);
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
UNLOCK(mpctx->lock);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1841,8 +1889,9 @@ isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG)
|
||||
item->next = mpctx->items;
|
||||
mpctx->items = item;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
UNLOCK(mpctx->lock);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1856,13 +1905,15 @@ isc_mempool_setfreemax(isc_mempool_t *mpctx0, unsigned int limit)
|
||||
|
||||
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
LOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
mpctx->freemax = limit;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
UNLOCK(mpctx->lock);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int
|
||||
@@ -1873,13 +1924,15 @@ isc_mempool_getfreemax(isc_mempool_t *mpctx0)
|
||||
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
|
||||
unsigned int freemax;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
LOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
freemax = mpctx->freemax;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
UNLOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
return (freemax);
|
||||
}
|
||||
@@ -1892,13 +1945,15 @@ isc_mempool_getfreecount(isc_mempool_t *mpctx0)
|
||||
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
|
||||
unsigned int freecount;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
LOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
freecount = mpctx->freecount;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
UNLOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
return (freecount);
|
||||
}
|
||||
@@ -1911,13 +1966,15 @@ isc_mempool_setmaxalloc(isc_mempool_t *mpctx0, unsigned int limit)
|
||||
|
||||
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
LOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
mpctx->maxalloc = limit;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
UNLOCK(mpctx->lock);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int
|
||||
@@ -1928,13 +1985,15 @@ isc_mempool_getmaxalloc(isc_mempool_t *mpctx0)
|
||||
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
|
||||
unsigned int maxalloc;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
LOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
maxalloc = mpctx->maxalloc;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
UNLOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
return (maxalloc);
|
||||
}
|
||||
@@ -1947,13 +2006,15 @@ isc_mempool_getallocated(isc_mempool_t *mpctx0)
|
||||
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
|
||||
unsigned int allocated;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
LOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
allocated = mpctx->allocated;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
UNLOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
return (allocated);
|
||||
}
|
||||
@@ -1966,13 +2027,15 @@ isc_mempool_setfillcount(isc_mempool_t *mpctx0, unsigned int limit)
|
||||
|
||||
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
LOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
mpctx->fillcount = limit;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
UNLOCK(mpctx->lock);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int
|
||||
@@ -1984,13 +2047,15 @@ isc_mempool_getfillcount(isc_mempool_t *mpctx0)
|
||||
|
||||
unsigned int fillcount;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
LOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
fillcount = mpctx->fillcount;
|
||||
|
||||
if (mpctx->lock != NULL)
|
||||
if (mpctx->lock != NULL) {
|
||||
UNLOCK(mpctx->lock);
|
||||
}
|
||||
|
||||
return (fillcount);
|
||||
}
|
||||
@@ -2018,7 +2083,7 @@ isc_mem_checkdestroyed(FILE *file)
|
||||
{
|
||||
#if !ISC_MEM_TRACKLINES
|
||||
UNUSED(file);
|
||||
#endif
|
||||
#endif /* if !ISC_MEM_TRACKLINES */
|
||||
|
||||
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
|
||||
|
||||
@@ -2028,7 +2093,7 @@ isc_mem_checkdestroyed(FILE *file)
|
||||
if (ISC_UNLIKELY((isc_mem_debugging & TRACE_OR_RECORD) != 0)) {
|
||||
print_contexts(file);
|
||||
}
|
||||
#endif
|
||||
#endif /* if ISC_MEM_TRACKLINES */
|
||||
INSIST(0);
|
||||
ISC_UNREACHABLE();
|
||||
}
|
||||
@@ -2088,7 +2153,7 @@ xml_renderctx(isc__mem_t *ctx, summarystat_t *summary, xmlTextWriterPtr writer)
|
||||
DEBUG_TABLE_COUNT * sizeof(debuglist_t) +
|
||||
ctx->debuglistcnt * sizeof(debuglink_t);
|
||||
}
|
||||
#endif
|
||||
#endif /* if ISC_MEM_TRACKLINES */
|
||||
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "references"));
|
||||
TRY0(xmlTextWriterWriteFormatString(
|
||||
writer, "%" PRIuFAST32,
|
||||
@@ -2131,8 +2196,9 @@ xml_renderctx(isc__mem_t *ctx, summarystat_t *summary, xmlTextWriterPtr writer)
|
||||
writer, "%" PRIu64 "",
|
||||
(uint64_t)ctx->basic_table_count * NUM_BASIC_BLOCKS *
|
||||
ctx->mem_target));
|
||||
} else
|
||||
} else {
|
||||
TRY0(xmlTextWriterWriteFormatString(writer, "%s", "-"));
|
||||
}
|
||||
TRY0(xmlTextWriterEndElement(writer)); /* blocksize */
|
||||
|
||||
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "pools"));
|
||||
@@ -2247,16 +2313,17 @@ json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array)
|
||||
summary->total += ctx->total;
|
||||
summary->inuse += ctx->inuse;
|
||||
summary->malloced += ctx->malloced;
|
||||
if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0)
|
||||
if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
|
||||
summary->blocksize += ctx->basic_table_count *
|
||||
NUM_BASIC_BLOCKS * ctx->mem_target;
|
||||
}
|
||||
#if ISC_MEM_TRACKLINES
|
||||
if (ctx->debuglist != NULL) {
|
||||
summary->contextsize +=
|
||||
DEBUG_TABLE_COUNT * sizeof(debuglist_t) +
|
||||
ctx->debuglistcnt * sizeof(debuglink_t);
|
||||
}
|
||||
#endif
|
||||
#endif /* if ISC_MEM_TRACKLINES */
|
||||
|
||||
ctxobj = json_object_new_object();
|
||||
CHECKMEM(ctxobj);
|
||||
@@ -2380,8 +2447,9 @@ isc_mem_renderjson(void *memobj0)
|
||||
return (ISC_R_SUCCESS);
|
||||
|
||||
error:
|
||||
if (ctxarray != NULL)
|
||||
if (ctxarray != NULL) {
|
||||
json_object_put(ctxarray);
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
#endif /* HAVE_JSON_C */
|
||||
@@ -2458,8 +2526,8 @@ isc__mem_printactive(isc_mem_t *ctx0, FILE *file)
|
||||
isc__mem_t *ctx = (isc__mem_t *)ctx0;
|
||||
|
||||
print_active(ctx, file);
|
||||
#else
|
||||
#else /* if ISC_MEM_TRACKLINES */
|
||||
UNUSED(ctx0);
|
||||
UNUSED(file);
|
||||
#endif
|
||||
#endif /* if ISC_MEM_TRACKLINES */
|
||||
}
|
||||
|
Reference in New Issue
Block a user