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

Merge branch 'cppcheck-1.90-warnings' into 'master'

Fix cppcheck 1.90 warnings

Closes #1590

See merge request isc-projects/bind9!2969
This commit is contained in:
Ondřej Surý
2020-02-04 10:10:48 +00:00
11 changed files with 203 additions and 175 deletions

View File

@@ -97,7 +97,7 @@ int main(int argc, char **argv)
UNUSED(argc); UNUSED(argc);
UNUSED(argv); UNUSED(argv);
target = target ? target + 1 : argv[0]; target = (target != NULL) ? target + 1 : argv[0];
if (strncmp(target, "lt-", 3) == 0) { if (strncmp(target, "lt-", 3) == 0) {
target += 3; target += 3;
} }

View File

@@ -1340,13 +1340,7 @@ dns_client_startresolve(dns_client_t *client, const dns_name_t *name,
ISC_LIST_INIT(event->answerlist); ISC_LIST_INIT(event->answerlist);
rctx = isc_mem_get(mctx, sizeof(*rctx)); rctx = isc_mem_get(mctx, sizeof(*rctx));
if (rctx == NULL) isc_mutex_init(&rctx->lock);
result = ISC_R_NOMEMORY;
else {
isc_mutex_init(&rctx->lock);
}
if (result != ISC_R_SUCCESS)
goto cleanup;
result = getrdataset(mctx, &rdataset); result = getrdataset(mctx, &rdataset);
if (result != ISC_R_SUCCESS) if (result != ISC_R_SUCCESS)
@@ -1748,13 +1742,7 @@ dns_client_startrequest(dns_client_t *client, dns_message_t *qmessage,
action, arg, sizeof(*event)); action, arg, sizeof(*event));
ctx = isc_mem_get(client->mctx, sizeof(*ctx)); ctx = isc_mem_get(client->mctx, sizeof(*ctx));
if (ctx == NULL) isc_mutex_init(&ctx->lock);
result = ISC_R_NOMEMORY;
else {
isc_mutex_init(&ctx->lock);
}
if (result != ISC_R_SUCCESS)
goto cleanup;
ctx->client = client; ctx->client = client;
ISC_LINK_INIT(ctx, link); ISC_LINK_INIT(ctx, link);
@@ -1787,16 +1775,13 @@ dns_client_startrequest(dns_client_t *client, dns_message_t *qmessage,
isc_refcount_decrement(&client->references); isc_refcount_decrement(&client->references);
cleanup: LOCK(&client->lock);
if (ctx != NULL) { ISC_LIST_UNLINK(client->reqctxs, ctx, link);
LOCK(&client->lock); UNLOCK(&client->lock);
ISC_LIST_UNLINK(client->reqctxs, ctx, link); isc_mutex_destroy(&ctx->lock);
UNLOCK(&client->lock); isc_mem_put(client->mctx, ctx, sizeof(*ctx));
isc_mutex_destroy(&ctx->lock);
isc_mem_put(client->mctx, ctx, sizeof(*ctx)); isc_event_free(ISC_EVENT_PTR(&event));
}
if (event != NULL)
isc_event_free(ISC_EVENT_PTR(&event));
isc_task_detach(&tclone); isc_task_detach(&tclone);
dns_view_detach(&view); dns_view_detach(&view);

View File

@@ -130,7 +130,7 @@ static isc_result_t
write_data(FILE *file, unsigned char *datap, void *arg, uint64_t *crc) { write_data(FILE *file, unsigned char *datap, void *arg, uint64_t *crc) {
isc_result_t result; isc_result_t result;
size_t ret = 0; size_t ret = 0;
data_holder_t *data = (data_holder_t *)datap; data_holder_t *data;
data_holder_t temp; data_holder_t temp;
off_t where; off_t where;
@@ -138,7 +138,8 @@ write_data(FILE *file, unsigned char *datap, void *arg, uint64_t *crc) {
REQUIRE(file != NULL); REQUIRE(file != NULL);
REQUIRE(crc != NULL); REQUIRE(crc != NULL);
REQUIRE(data != NULL); REQUIRE(datap != NULL);
data = (data_holder_t *)datap;
REQUIRE((data->len == 0 && data->data == NULL) || REQUIRE((data->len == 0 && data->data == NULL) ||
(data->len != 0 && data->data != NULL)); (data->len != 0 && data->data != NULL));
@@ -402,7 +403,9 @@ deserialize_corrupt_test(void **state) {
close(fd); close(fd);
/* Randomly fuzz a portion of the memory */ /* Randomly fuzz a portion of the memory */
/* cppcheck-suppress nullPointerArithmeticRedundantCheck */
p = base + (isc_random_uniform(filesize)); p = base + (isc_random_uniform(filesize));
/* cppcheck-suppress nullPointerArithmeticRedundantCheck */
q = base + filesize; q = base + filesize;
q -= (isc_random_uniform(q - p)); q -= (isc_random_uniform(q - p));
while (p++ < q) { while (p++ < q) {

View File

@@ -1122,7 +1122,7 @@ free_element_heap(void *element, void *uap) {
} }
static bool static bool
checknext(const vctx_t *vctx, const struct nsec3_chain_fixed *first, _checknext(const vctx_t *vctx, const struct nsec3_chain_fixed *first,
const struct nsec3_chain_fixed *e) const struct nsec3_chain_fixed *e)
{ {
char buf[512]; char buf[512];
@@ -1162,6 +1162,37 @@ checknext(const vctx_t *vctx, const struct nsec3_chain_fixed *first,
return (false); return (false);
} }
static inline bool
checknext(isc_mem_t *mctx,
const vctx_t *vctx,
const struct nsec3_chain_fixed *first,
struct nsec3_chain_fixed *prev,
const struct nsec3_chain_fixed *cur)
{
bool result = _checknext(vctx, prev, cur);
if (prev != first) {
free_element(mctx, prev);
}
return (result);
}
static inline bool
checklast(isc_mem_t *mctx,
const vctx_t *vctx,
struct nsec3_chain_fixed *first,
struct nsec3_chain_fixed *prev)
{
bool result = _checknext(vctx, prev, first);
if (prev != first) {
free_element(mctx, prev);
}
free_element(mctx, first);
return (result);
}
static isc_result_t static isc_result_t
verify_nsec3_chains(const vctx_t *vctx, isc_mem_t *mctx) { verify_nsec3_chains(const vctx_t *vctx, isc_mem_t *mctx) {
isc_result_t result = ISC_R_SUCCESS; isc_result_t result = ISC_R_SUCCESS;
@@ -1214,39 +1245,27 @@ verify_nsec3_chains(const vctx_t *vctx, isc_mem_t *mctx) {
"not equal"); "not equal");
result = ISC_R_FAILURE; result = ISC_R_FAILURE;
} }
if (first == NULL || newchain(first, e)) {
if (prev != NULL) { if (first == NULL) {
if (!checknext(vctx, prev, first)) {
result = ISC_R_FAILURE;
}
if (prev != first) {
free_element(mctx, prev);
}
}
if (first != NULL) {
free_element(mctx, first);
}
prev = first = e; prev = first = e;
continue; } else if (newchain(first, e)) {
if (!checklast(mctx, vctx, first, prev)) {
result = ISC_R_FAILURE;
}
prev = first = e;
} else {
if (!checknext(mctx, vctx, first, prev, e)) {
result = ISC_R_FAILURE;
}
prev = e;
} }
if (!checknext(vctx, prev, e)) {
result = ISC_R_FAILURE;
}
if (prev != first) {
free_element(mctx, prev);
}
prev = e;
} }
if (prev != NULL) { if (prev != NULL) {
if (!checknext(vctx, prev, first)) { if (!checklast(mctx, vctx, first, prev)) {
result = ISC_R_FAILURE; result = ISC_R_FAILURE;
} }
if (prev != first) {
free_element(mctx, prev);
}
}
if (first != NULL) {
free_element(mctx, first);
} }
do { do {
if (f != NULL) { if (f != NULL) {

View File

@@ -15,6 +15,10 @@
/*% /*%
* Performance * Performance
*/ */
#ifdef CPPCHECK
#define ISC_LIKELY(x) (x)
#define ISC_UNLIKELY(x) (x)
#else
#ifdef HAVE_BUILTIN_EXPECT #ifdef HAVE_BUILTIN_EXPECT
#define ISC_LIKELY(x) __builtin_expect(!!(x), 1) #define ISC_LIKELY(x) __builtin_expect(!!(x), 1)
#define ISC_UNLIKELY(x) __builtin_expect(!!(x), 0) #define ISC_UNLIKELY(x) __builtin_expect(!!(x), 0)
@@ -22,5 +26,6 @@
#define ISC_LIKELY(x) (x) #define ISC_LIKELY(x) (x)
#define ISC_UNLIKELY(x) (x) #define ISC_UNLIKELY(x) (x)
#endif #endif
#endif
#endif /* ISC_LIKELY_H */ #endif /* ISC_LIKELY_H */

View File

@@ -285,12 +285,17 @@ extern void mock_assert(const int result, const char* const expression,
#ifdef UNIT_TESTING #ifdef UNIT_TESTING
#define RUNTIME_CHECK(expression) \ #define RUNTIME_CHECK(expression) \
mock_assert((int)(expression), #expression, __FILE__, __LINE__) ((!(expression)) ? \
(mock_assert(0, #expression, __FILE__, __LINE__), abort()) : (void)0)
#else /* UNIT_TESTING */ #else /* UNIT_TESTING */
#ifndef CPPCHECK
/*% Runtime Check */ /*% Runtime Check */
#define RUNTIME_CHECK(cond) ISC_ERROR_RUNTIMECHECK(cond) #define RUNTIME_CHECK(cond) ISC_ERROR_RUNTIMECHECK(cond)
#else
#define RUNTIME_CHECK(e) if (!(e)) abort()
#endif
#endif /* UNIT_TESTING */ #endif /* UNIT_TESTING */

View File

@@ -126,6 +126,11 @@ static isc_mutex_t contextslock;
*/ */
static uint64_t totallost; static uint64_t totallost;
/*%
* Memory allocation and free function definitions.
* isc__memalloc_t must deal with memory allocation failure
* and must never return NULL.
*/
typedef void * (*isc__memalloc_t)(size_t); typedef void * (*isc__memalloc_t)(size_t);
typedef void (*isc__memfree_t)(void *); typedef void (*isc__memfree_t)(void *);
@@ -363,7 +368,6 @@ more_basic_blocks(isc__mem_t *ctx) {
if (ctx->basic_table_count == ctx->basic_table_size) { if (ctx->basic_table_count == ctx->basic_table_size) {
table_size = ctx->basic_table_size + TABLE_INCREMENT; table_size = ctx->basic_table_size + TABLE_INCREMENT;
table = (ctx->memalloc)(table_size * sizeof(unsigned char *)); table = (ctx->memalloc)(table_size * sizeof(unsigned char *));
RUNTIME_CHECK(table != NULL);
ctx->malloced += 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; ctx->maxmalloced = ctx->malloced;
@@ -380,7 +384,6 @@ more_basic_blocks(isc__mem_t *ctx) {
} }
tmp = (ctx->memalloc)(NUM_BASIC_BLOCKS * ctx->mem_target); tmp = (ctx->memalloc)(NUM_BASIC_BLOCKS * ctx->mem_target);
RUNTIME_CHECK(tmp != NULL);
ctx->total += 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[ctx->basic_table_count] = tmp;
ctx->basic_table_count++; ctx->basic_table_count++;
@@ -473,7 +476,6 @@ mem_getunlocked(isc__mem_t *ctx, size_t size) {
* memget() was called on something beyond our upper limit. * memget() was called on something beyond our upper limit.
*/ */
ret = (ctx->memalloc)(size); ret = (ctx->memalloc)(size);
RUNTIME_CHECK(ret != NULL);
ctx->total += size; ctx->total += size;
ctx->inuse += size; ctx->inuse += size;
ctx->stats[ctx->max_size].gets++; ctx->stats[ctx->max_size].gets++;
@@ -596,7 +598,6 @@ mem_get(isc__mem_t *ctx, size_t size) {
size += 1; size += 1;
#endif #endif
ret = (ctx->memalloc)(size); ret = (ctx->memalloc)(size);
RUNTIME_CHECK(ret != NULL);
if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) { if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) {
if (ISC_LIKELY(ret != NULL)) if (ISC_LIKELY(ret != NULL))
@@ -723,10 +724,10 @@ initialize_action(void) {
static void static void
mem_create(isc_mem_t **ctxp, unsigned int flags) mem_create(isc_mem_t **ctxp, unsigned int flags)
{ {
isc__mem_t *ctx;
REQUIRE(ctxp != NULL && *ctxp == NULL); REQUIRE(ctxp != NULL && *ctxp == NULL);
isc__mem_t *ctx;
STATIC_ASSERT((ALIGNMENT_SIZE & (ALIGNMENT_SIZE - 1)) == 0, STATIC_ASSERT((ALIGNMENT_SIZE & (ALIGNMENT_SIZE - 1)) == 0,
"wrong alignment size"); "wrong alignment size");
@@ -774,7 +775,6 @@ mem_create(isc_mem_t **ctxp, unsigned int flags)
ctx->highest = NULL; ctx->highest = NULL;
ctx->stats = (ctx->memalloc)((ctx->max_size+1) * sizeof(struct stats)); ctx->stats = (ctx->memalloc)((ctx->max_size+1) * sizeof(struct stats));
RUNTIME_CHECK(ctx->stats != NULL);
memset(ctx->stats, 0, (ctx->max_size + 1) * sizeof(struct stats)); memset(ctx->stats, 0, (ctx->max_size + 1) * sizeof(struct stats));
ctx->malloced += (ctx->max_size+1) * sizeof(struct stats); ctx->malloced += (ctx->max_size+1) * sizeof(struct stats);
@@ -784,7 +784,6 @@ mem_create(isc_mem_t **ctxp, unsigned int flags)
ctx->mem_target = DEF_MEM_TARGET; ctx->mem_target = DEF_MEM_TARGET;
ctx->freelists = (ctx->memalloc)(ctx->max_size * ctx->freelists = (ctx->memalloc)(ctx->max_size *
sizeof(element *)); sizeof(element *));
RUNTIME_CHECK(ctx->freelists != NULL);
memset(ctx->freelists, 0, memset(ctx->freelists, 0,
ctx->max_size * sizeof(element *)); ctx->max_size * sizeof(element *));
ctx->malloced += ctx->max_size * sizeof(element *); ctx->malloced += ctx->max_size * sizeof(element *);
@@ -797,7 +796,6 @@ mem_create(isc_mem_t **ctxp, unsigned int flags)
ctx->debuglist = (ctx->memalloc)((DEBUG_TABLE_COUNT * ctx->debuglist = (ctx->memalloc)((DEBUG_TABLE_COUNT *
sizeof(debuglist_t))); sizeof(debuglist_t)));
RUNTIME_CHECK(ctx->debuglist != NULL);
for (i = 0; i < DEBUG_TABLE_COUNT; i++) for (i = 0; i < DEBUG_TABLE_COUNT; i++)
ISC_LIST_INIT(ctx->debuglist[i]); ISC_LIST_INIT(ctx->debuglist[i]);
ctx->malloced += DEBUG_TABLE_COUNT * sizeof(debuglist_t); ctx->malloced += DEBUG_TABLE_COUNT * sizeof(debuglist_t);
@@ -895,11 +893,11 @@ destroy(isc__mem_t *ctx) {
void void
isc_mem_attach(isc_mem_t *source0, isc_mem_t **targetp) { isc_mem_attach(isc_mem_t *source0, isc_mem_t **targetp) {
isc__mem_t *source = (isc__mem_t *)source0; REQUIRE(VALID_CONTEXT(source0));
REQUIRE(VALID_CONTEXT(source));
REQUIRE(targetp != NULL && *targetp == NULL); REQUIRE(targetp != NULL && *targetp == NULL);
isc__mem_t *source = (isc__mem_t *)source0;
isc_refcount_increment(&source->references); isc_refcount_increment(&source->references);
*targetp = (isc_mem_t *)source; *targetp = (isc_mem_t *)source;
@@ -908,6 +906,7 @@ isc_mem_attach(isc_mem_t *source0, isc_mem_t **targetp) {
void void
isc_mem_detach(isc_mem_t **ctxp) { isc_mem_detach(isc_mem_t **ctxp) {
REQUIRE(ctxp != NULL && VALID_CONTEXT(*ctxp)); REQUIRE(ctxp != NULL && VALID_CONTEXT(*ctxp));
isc__mem_t *ctx = (isc__mem_t *)*ctxp; isc__mem_t *ctx = (isc__mem_t *)*ctxp;
*ctxp = NULL; *ctxp = NULL;
@@ -931,6 +930,7 @@ void
isc___mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG) { isc___mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG) {
REQUIRE(ctxp != NULL && VALID_CONTEXT(*ctxp)); REQUIRE(ctxp != NULL && VALID_CONTEXT(*ctxp));
REQUIRE(ptr != NULL); REQUIRE(ptr != NULL);
isc__mem_t *ctx = (isc__mem_t *)*ctxp; isc__mem_t *ctx = (isc__mem_t *)*ctxp;
*ctxp = NULL; *ctxp = NULL;
@@ -970,16 +970,14 @@ destroy:
void void
isc_mem_destroy(isc_mem_t **ctxp) { isc_mem_destroy(isc_mem_t **ctxp) {
isc__mem_t *ctx;
/* /*
* This routine provides legacy support for callers who use mctxs * This routine provides legacy support for callers who use mctxs
* without attaching/detaching. * without attaching/detaching.
*/ */
REQUIRE(ctxp != NULL); REQUIRE(ctxp != NULL && VALID_CONTEXT(*ctxp));
ctx = (isc__mem_t *)*ctxp;
REQUIRE(VALID_CONTEXT(ctx)); isc__mem_t *ctx = (isc__mem_t *)*ctxp;
#if ISC_MEM_TRACKLINES #if ISC_MEM_TRACKLINES
if (isc_refcount_decrement(&ctx->references) > 1) { if (isc_refcount_decrement(&ctx->references) > 1) {
@@ -996,12 +994,12 @@ isc_mem_destroy(isc_mem_t **ctxp) {
void * void *
isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) { isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) {
REQUIRE(VALID_CONTEXT(ctx0));
isc__mem_t *ctx = (isc__mem_t *)ctx0; isc__mem_t *ctx = (isc__mem_t *)ctx0;
void *ptr; void *ptr;
bool call_water = false; bool call_water = false;
REQUIRE(VALID_CONTEXT(ctx));
if (ISC_UNLIKELY((isc_mem_debugging & 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)); return (isc__mem_allocate(ctx0, size FLARG_PASS));
@@ -1040,14 +1038,14 @@ isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) {
void void
isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) { isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) {
REQUIRE(VALID_CONTEXT(ctx0));
REQUIRE(ptr != NULL);
isc__mem_t *ctx = (isc__mem_t *)ctx0; isc__mem_t *ctx = (isc__mem_t *)ctx0;
bool call_water = false; bool call_water = false;
size_info *si; size_info *si;
size_t oldsize; size_t oldsize;
REQUIRE(VALID_CONTEXT(ctx));
REQUIRE(ptr != NULL);
if (ISC_UNLIKELY((isc_mem_debugging & if (ISC_UNLIKELY((isc_mem_debugging &
(ISC_MEM_DEBUGSIZE|ISC_MEM_DEBUGCTX)) != 0)) (ISC_MEM_DEBUGSIZE|ISC_MEM_DEBUGCTX)) != 0))
{ {
@@ -1092,9 +1090,9 @@ isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) {
void void
isc_mem_waterack(isc_mem_t *ctx0, int flag) { isc_mem_waterack(isc_mem_t *ctx0, int flag) {
isc__mem_t *ctx = (isc__mem_t *)ctx0; REQUIRE(VALID_CONTEXT(ctx0));
REQUIRE(VALID_CONTEXT(ctx)); isc__mem_t *ctx = (isc__mem_t *)ctx0;
MCTXLOCK(ctx); MCTXLOCK(ctx);
if (flag == ISC_MEM_LOWATER) if (flag == ISC_MEM_LOWATER)
@@ -1144,12 +1142,13 @@ print_active(isc__mem_t *mctx, FILE *out) {
*/ */
void void
isc_mem_stats(isc_mem_t *ctx0, FILE *out) { isc_mem_stats(isc_mem_t *ctx0, FILE *out) {
REQUIRE(VALID_CONTEXT(ctx0));
isc__mem_t *ctx = (isc__mem_t *)ctx0; isc__mem_t *ctx = (isc__mem_t *)ctx0;
size_t i; size_t i;
const struct stats *s; const struct stats *s;
const isc__mempool_t *pool; const isc__mempool_t *pool;
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx); MCTXLOCK(ctx);
for (i = 0; i <= ctx->max_size; i++) { for (i = 0; i <= ctx->max_size; i++) {
@@ -1232,12 +1231,12 @@ mem_allocateunlocked(isc_mem_t *ctx0, size_t size) {
void * void *
isc___mem_allocate(isc_mem_t *ctx0, size_t size FLARG) { isc___mem_allocate(isc_mem_t *ctx0, size_t size FLARG) {
REQUIRE(VALID_CONTEXT(ctx0));
isc__mem_t *ctx = (isc__mem_t *)ctx0; isc__mem_t *ctx = (isc__mem_t *)ctx0;
size_info *si; size_info *si;
bool call_water = false; bool call_water = false;
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx); MCTXLOCK(ctx);
si = mem_allocateunlocked((isc_mem_t *)ctx, size); si = mem_allocateunlocked((isc_mem_t *)ctx, size);
if (((ctx->flags & ISC_MEMFLAG_INTERNAL) == 0)) { if (((ctx->flags & ISC_MEMFLAG_INTERNAL) == 0)) {
@@ -1274,12 +1273,11 @@ isc___mem_allocate(isc_mem_t *ctx0, size_t size FLARG) {
void * void *
isc___mem_reallocate(isc_mem_t *ctx0, void *ptr, size_t size FLARG) { isc___mem_reallocate(isc_mem_t *ctx0, void *ptr, size_t size FLARG) {
isc__mem_t *ctx = (isc__mem_t *)ctx0; REQUIRE(VALID_CONTEXT(ctx0));
void *new_ptr = NULL; void *new_ptr = NULL;
size_t oldsize, copysize; size_t oldsize, copysize;
REQUIRE(VALID_CONTEXT(ctx));
/* /*
* This function emulates the realloc(3) standard library function: * This function emulates the realloc(3) standard library function:
* - if size > 0, allocate new memory; and if ptr is non NULL, copy * - if size > 0, allocate new memory; and if ptr is non NULL, copy
@@ -1315,14 +1313,14 @@ isc___mem_reallocate(isc_mem_t *ctx0, void *ptr, size_t size FLARG) {
void void
isc___mem_free(isc_mem_t *ctx0, void *ptr FLARG) { isc___mem_free(isc_mem_t *ctx0, void *ptr FLARG) {
REQUIRE(VALID_CONTEXT(ctx0));
REQUIRE(ptr != NULL);
isc__mem_t *ctx = (isc__mem_t *)ctx0; isc__mem_t *ctx = (isc__mem_t *)ctx0;
size_info *si; size_info *si;
size_t size; size_t size;
bool call_water= false; bool call_water= false;
REQUIRE(VALID_CONTEXT(ctx));
REQUIRE(ptr != NULL);
if (ISC_UNLIKELY((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0)) { if (ISC_UNLIKELY((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0)) {
si = &(((size_info *)ptr)[-2]); si = &(((size_info *)ptr)[-2]);
REQUIRE(si->u.ctx == ctx); REQUIRE(si->u.ctx == ctx);
@@ -1373,13 +1371,13 @@ isc___mem_free(isc_mem_t *ctx0, void *ptr FLARG) {
char * char *
isc___mem_strdup(isc_mem_t *mctx0, const char *s FLARG) { isc___mem_strdup(isc_mem_t *mctx0, const char *s FLARG) {
REQUIRE(VALID_CONTEXT(mctx0));
REQUIRE(s != NULL);
isc__mem_t *mctx = (isc__mem_t *)mctx0; isc__mem_t *mctx = (isc__mem_t *)mctx0;
size_t len; size_t len;
char *ns; char *ns;
REQUIRE(VALID_CONTEXT(mctx));
REQUIRE(s != NULL);
len = strlen(s) + 1; len = strlen(s) + 1;
ns = isc__mem_allocate((isc_mem_t *)mctx, len FLARG_PASS); ns = isc__mem_allocate((isc_mem_t *)mctx, len FLARG_PASS);
@@ -1392,9 +1390,10 @@ isc___mem_strdup(isc_mem_t *mctx0, const char *s FLARG) {
void void
isc_mem_setdestroycheck(isc_mem_t *ctx0, bool flag) { isc_mem_setdestroycheck(isc_mem_t *ctx0, bool flag) {
REQUIRE(VALID_CONTEXT(ctx0));
isc__mem_t *ctx = (isc__mem_t *)ctx0; isc__mem_t *ctx = (isc__mem_t *)ctx0;
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx); MCTXLOCK(ctx);
ctx->checkfree = flag; ctx->checkfree = flag;
@@ -1404,10 +1403,11 @@ isc_mem_setdestroycheck(isc_mem_t *ctx0, bool flag) {
size_t size_t
isc_mem_inuse(isc_mem_t *ctx0) { isc_mem_inuse(isc_mem_t *ctx0) {
REQUIRE(VALID_CONTEXT(ctx0));
isc__mem_t *ctx = (isc__mem_t *)ctx0; isc__mem_t *ctx = (isc__mem_t *)ctx0;
size_t inuse; size_t inuse;
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx); MCTXLOCK(ctx);
inuse = ctx->inuse; inuse = ctx->inuse;
@@ -1419,10 +1419,11 @@ isc_mem_inuse(isc_mem_t *ctx0) {
size_t size_t
isc_mem_maxinuse(isc_mem_t *ctx0) { isc_mem_maxinuse(isc_mem_t *ctx0) {
REQUIRE(VALID_CONTEXT(ctx0));
isc__mem_t *ctx = (isc__mem_t *)ctx0; isc__mem_t *ctx = (isc__mem_t *)ctx0;
size_t maxinuse; size_t maxinuse;
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx); MCTXLOCK(ctx);
maxinuse = ctx->maxinuse; maxinuse = ctx->maxinuse;
@@ -1434,10 +1435,11 @@ isc_mem_maxinuse(isc_mem_t *ctx0) {
size_t size_t
isc_mem_total(isc_mem_t *ctx0) { isc_mem_total(isc_mem_t *ctx0) {
REQUIRE(VALID_CONTEXT(ctx0));
isc__mem_t *ctx = (isc__mem_t *)ctx0; isc__mem_t *ctx = (isc__mem_t *)ctx0;
size_t total; size_t total;
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx); MCTXLOCK(ctx);
total = ctx->total; total = ctx->total;
@@ -1451,14 +1453,14 @@ void
isc_mem_setwater(isc_mem_t *ctx0, isc_mem_water_t water, void *water_arg, isc_mem_setwater(isc_mem_t *ctx0, isc_mem_water_t water, void *water_arg,
size_t hiwater, size_t lowater) size_t hiwater, size_t lowater)
{ {
REQUIRE(VALID_CONTEXT(ctx0));
REQUIRE(hiwater >= lowater);
isc__mem_t *ctx = (isc__mem_t *)ctx0; isc__mem_t *ctx = (isc__mem_t *)ctx0;
bool callwater = false; bool callwater = false;
isc_mem_water_t oldwater; isc_mem_water_t oldwater;
void *oldwater_arg; void *oldwater_arg;
REQUIRE(VALID_CONTEXT(ctx));
REQUIRE(hiwater >= lowater);
MCTXLOCK(ctx); MCTXLOCK(ctx);
oldwater = ctx->water; oldwater = ctx->water;
oldwater_arg = ctx->water_arg; oldwater_arg = ctx->water_arg;
@@ -1486,9 +1488,9 @@ isc_mem_setwater(isc_mem_t *ctx0, isc_mem_water_t water, void *water_arg,
bool bool
isc_mem_isovermem(isc_mem_t *ctx0) { isc_mem_isovermem(isc_mem_t *ctx0) {
isc__mem_t *ctx = (isc__mem_t *)ctx0; REQUIRE(VALID_CONTEXT(ctx0));
REQUIRE(VALID_CONTEXT(ctx)); isc__mem_t *ctx = (isc__mem_t *)ctx0;
/* /*
* We don't bother to lock the context because 100% accuracy isn't * We don't bother to lock the context because 100% accuracy isn't
@@ -1500,9 +1502,9 @@ isc_mem_isovermem(isc_mem_t *ctx0) {
void void
isc_mem_setname(isc_mem_t *ctx0, const char *name, void *tag) { isc_mem_setname(isc_mem_t *ctx0, const char *name, void *tag) {
isc__mem_t *ctx = (isc__mem_t *)ctx0; REQUIRE(VALID_CONTEXT(ctx0));
REQUIRE(VALID_CONTEXT(ctx)); isc__mem_t *ctx = (isc__mem_t *)ctx0;
LOCK(&ctx->lock); LOCK(&ctx->lock);
strlcpy(ctx->name, name, sizeof(ctx->name)); strlcpy(ctx->name, name, sizeof(ctx->name));
@@ -1512,9 +1514,9 @@ isc_mem_setname(isc_mem_t *ctx0, const char *name, void *tag) {
const char * const char *
isc_mem_getname(isc_mem_t *ctx0) { isc_mem_getname(isc_mem_t *ctx0) {
isc__mem_t *ctx = (isc__mem_t *)ctx0; REQUIRE(VALID_CONTEXT(ctx0));
REQUIRE(VALID_CONTEXT(ctx)); isc__mem_t *ctx = (isc__mem_t *)ctx0;
if (ctx->name[0] == 0) if (ctx->name[0] == 0)
return (""); return ("");
@@ -1524,9 +1526,9 @@ isc_mem_getname(isc_mem_t *ctx0) {
void * void *
isc_mem_gettag(isc_mem_t *ctx0) { isc_mem_gettag(isc_mem_t *ctx0) {
isc__mem_t *ctx = (isc__mem_t *)ctx0; REQUIRE(VALID_CONTEXT(ctx0));
REQUIRE(VALID_CONTEXT(ctx)); isc__mem_t *ctx = (isc__mem_t *)ctx0;
return (ctx->tag); return (ctx->tag);
} }
@@ -1537,19 +1539,18 @@ isc_mem_gettag(isc_mem_t *ctx0) {
void void
isc_mempool_create(isc_mem_t *mctx0, size_t size, isc_mempool_t **mpctxp) { isc_mempool_create(isc_mem_t *mctx0, size_t size, isc_mempool_t **mpctxp) {
isc__mem_t *mctx = (isc__mem_t *)mctx0; REQUIRE(VALID_CONTEXT(mctx0));
isc__mempool_t *mpctx;
REQUIRE(VALID_CONTEXT(mctx));
REQUIRE(size > 0U); REQUIRE(size > 0U);
REQUIRE(mpctxp != NULL && *mpctxp == NULL); REQUIRE(mpctxp != NULL && *mpctxp == NULL);
isc__mem_t *mctx = (isc__mem_t *)mctx0;
isc__mempool_t *mpctx;
/* /*
* Allocate space for this pool, initialize values, and if all works * Allocate space for this pool, initialize values, and if all works
* well, attach to the memory context. * well, attach to the memory context.
*/ */
mpctx = isc_mem_get((isc_mem_t *)mctx, sizeof(isc__mempool_t)); mpctx = isc_mem_get((isc_mem_t *)mctx, sizeof(isc__mempool_t));
RUNTIME_CHECK(mpctx != NULL);
mpctx->common.impmagic = MEMPOOL_MAGIC; mpctx->common.impmagic = MEMPOOL_MAGIC;
mpctx->common.magic = ISCAPI_MPOOL_MAGIC; mpctx->common.magic = ISCAPI_MPOOL_MAGIC;
@@ -1583,10 +1584,10 @@ isc_mempool_create(isc_mem_t *mctx0, size_t size, isc_mempool_t **mpctxp) {
void void
isc_mempool_setname(isc_mempool_t *mpctx0, const char *name) { isc_mempool_setname(isc_mempool_t *mpctx0, const char *name) {
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; REQUIRE(VALID_MEMPOOL(mpctx0));
REQUIRE(name != NULL); REQUIRE(name != NULL);
REQUIRE(VALID_MEMPOOL(mpctx));
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
#if ISC_MEMPOOL_NAMES #if ISC_MEMPOOL_NAMES
if (mpctx->lock != NULL) if (mpctx->lock != NULL)
@@ -1604,14 +1605,15 @@ isc_mempool_setname(isc_mempool_t *mpctx0, const char *name) {
void void
isc_mempool_destroy(isc_mempool_t **mpctxp) { isc_mempool_destroy(isc_mempool_t **mpctxp) {
REQUIRE(mpctxp != NULL);
REQUIRE(VALID_MEMPOOL(*mpctxp));
isc__mempool_t *mpctx; isc__mempool_t *mpctx;
isc__mem_t *mctx; isc__mem_t *mctx;
isc_mutex_t *lock; isc_mutex_t *lock;
element *item; element *item;
REQUIRE(mpctxp != NULL);
mpctx = (isc__mempool_t *)*mpctxp; mpctx = (isc__mempool_t *)*mpctxp;
REQUIRE(VALID_MEMPOOL(mpctx));
#if ISC_MEMPOOL_NAMES #if ISC_MEMPOOL_NAMES
if (mpctx->allocated > 0) if (mpctx->allocated > 0)
UNEXPECTED_ERROR(__FILE__, __LINE__, UNEXPECTED_ERROR(__FILE__, __LINE__,
@@ -1668,24 +1670,25 @@ isc_mempool_destroy(isc_mempool_t **mpctxp) {
void void
isc_mempool_associatelock(isc_mempool_t *mpctx0, isc_mutex_t *lock) { isc_mempool_associatelock(isc_mempool_t *mpctx0, isc_mutex_t *lock) {
REQUIRE(VALID_MEMPOOL(mpctx0));
REQUIRE(lock != NULL);
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
REQUIRE(VALID_MEMPOOL(mpctx));
REQUIRE(mpctx->lock == NULL); REQUIRE(mpctx->lock == NULL);
REQUIRE(lock != NULL);
mpctx->lock = lock; mpctx->lock = lock;
} }
void * void *
isc__mempool_get(isc_mempool_t *mpctx0 FLARG) { isc__mempool_get(isc_mempool_t *mpctx0 FLARG) {
REQUIRE(VALID_MEMPOOL(mpctx0));
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
element *item; element *item;
isc__mem_t *mctx; isc__mem_t *mctx;
unsigned int i; unsigned int i;
REQUIRE(VALID_MEMPOOL(mpctx));
mctx = mpctx->mctx; mctx = mpctx->mctx;
if (mpctx->lock != NULL) if (mpctx->lock != NULL)
@@ -1755,14 +1758,12 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG) {
/* coverity[+free : arg-1] */ /* coverity[+free : arg-1] */
void void
isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG) { isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG) {
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; REQUIRE(VALID_MEMPOOL(mpctx0));
isc__mem_t *mctx;
element *item;
REQUIRE(VALID_MEMPOOL(mpctx));
REQUIRE(mem != NULL); REQUIRE(mem != NULL);
mctx = mpctx->mctx; isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
isc__mem_t *mctx = mpctx->mctx;
element *item;
if (mpctx->lock != NULL) if (mpctx->lock != NULL)
LOCK(mpctx->lock); LOCK(mpctx->lock);
@@ -1813,9 +1814,9 @@ isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG) {
void void
isc_mempool_setfreemax(isc_mempool_t *mpctx0, unsigned int limit) { isc_mempool_setfreemax(isc_mempool_t *mpctx0, unsigned int limit) {
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; REQUIRE(VALID_MEMPOOL(mpctx0));
REQUIRE(VALID_MEMPOOL(mpctx)); isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
if (mpctx->lock != NULL) if (mpctx->lock != NULL)
LOCK(mpctx->lock); LOCK(mpctx->lock);
@@ -1828,11 +1829,11 @@ isc_mempool_setfreemax(isc_mempool_t *mpctx0, unsigned int limit) {
unsigned int unsigned int
isc_mempool_getfreemax(isc_mempool_t *mpctx0) { isc_mempool_getfreemax(isc_mempool_t *mpctx0) {
REQUIRE(VALID_MEMPOOL(mpctx0));
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
unsigned int freemax; unsigned int freemax;
REQUIRE(VALID_MEMPOOL(mpctx));
if (mpctx->lock != NULL) if (mpctx->lock != NULL)
LOCK(mpctx->lock); LOCK(mpctx->lock);
@@ -1846,10 +1847,11 @@ isc_mempool_getfreemax(isc_mempool_t *mpctx0) {
unsigned int unsigned int
isc_mempool_getfreecount(isc_mempool_t *mpctx0) { isc_mempool_getfreecount(isc_mempool_t *mpctx0) {
REQUIRE(VALID_MEMPOOL(mpctx0));
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
unsigned int freecount; unsigned int freecount;
REQUIRE(VALID_MEMPOOL(mpctx));
if (mpctx->lock != NULL) if (mpctx->lock != NULL)
LOCK(mpctx->lock); LOCK(mpctx->lock);
@@ -1864,11 +1866,10 @@ isc_mempool_getfreecount(isc_mempool_t *mpctx0) {
void void
isc_mempool_setmaxalloc(isc_mempool_t *mpctx0, unsigned int limit) { isc_mempool_setmaxalloc(isc_mempool_t *mpctx0, unsigned int limit) {
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; REQUIRE(VALID_MEMPOOL(mpctx0));
REQUIRE(limit > 0); REQUIRE(limit > 0);
REQUIRE(VALID_MEMPOOL(mpctx)); isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
if (mpctx->lock != NULL) if (mpctx->lock != NULL)
LOCK(mpctx->lock); LOCK(mpctx->lock);
@@ -1881,11 +1882,11 @@ isc_mempool_setmaxalloc(isc_mempool_t *mpctx0, unsigned int limit) {
unsigned int unsigned int
isc_mempool_getmaxalloc(isc_mempool_t *mpctx0) { isc_mempool_getmaxalloc(isc_mempool_t *mpctx0) {
REQUIRE(VALID_MEMPOOL(mpctx0));
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
unsigned int maxalloc; unsigned int maxalloc;
REQUIRE(VALID_MEMPOOL(mpctx));
if (mpctx->lock != NULL) if (mpctx->lock != NULL)
LOCK(mpctx->lock); LOCK(mpctx->lock);
@@ -1899,10 +1900,11 @@ isc_mempool_getmaxalloc(isc_mempool_t *mpctx0) {
unsigned int unsigned int
isc_mempool_getallocated(isc_mempool_t *mpctx0) { isc_mempool_getallocated(isc_mempool_t *mpctx0) {
REQUIRE(VALID_MEMPOOL(mpctx0));
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
unsigned int allocated; unsigned int allocated;
REQUIRE(VALID_MEMPOOL(mpctx));
if (mpctx->lock != NULL) if (mpctx->lock != NULL)
LOCK(mpctx->lock); LOCK(mpctx->lock);
@@ -1917,10 +1919,10 @@ isc_mempool_getallocated(isc_mempool_t *mpctx0) {
void void
isc_mempool_setfillcount(isc_mempool_t *mpctx0, unsigned int limit) { isc_mempool_setfillcount(isc_mempool_t *mpctx0, unsigned int limit) {
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; REQUIRE(VALID_MEMPOOL(mpctx0));
REQUIRE(limit > 0); REQUIRE(limit > 0);
REQUIRE(VALID_MEMPOOL(mpctx));
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
if (mpctx->lock != NULL) if (mpctx->lock != NULL)
LOCK(mpctx->lock); LOCK(mpctx->lock);
@@ -1933,12 +1935,12 @@ isc_mempool_setfillcount(isc_mempool_t *mpctx0, unsigned int limit) {
unsigned int unsigned int
isc_mempool_getfillcount(isc_mempool_t *mpctx0) { isc_mempool_getfillcount(isc_mempool_t *mpctx0) {
REQUIRE(VALID_MEMPOOL(mpctx0));
isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0;
unsigned int fillcount; unsigned int fillcount;
REQUIRE(VALID_MEMPOOL(mpctx));
if (mpctx->lock != NULL) if (mpctx->lock != NULL)
LOCK(mpctx->lock); LOCK(mpctx->lock);
@@ -2011,10 +2013,10 @@ static int
xml_renderctx(isc__mem_t *ctx, summarystat_t *summary, xml_renderctx(isc__mem_t *ctx, summarystat_t *summary,
xmlTextWriterPtr writer) xmlTextWriterPtr writer)
{ {
int xmlrc;
REQUIRE(VALID_CONTEXT(ctx)); REQUIRE(VALID_CONTEXT(ctx));
int xmlrc;
MCTXLOCK(ctx); MCTXLOCK(ctx);
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "context")); TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "context"));
@@ -2196,13 +2198,13 @@ isc_mem_renderxml(void *writer0) {
static isc_result_t static isc_result_t
json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array) { json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array) {
json_object *ctxobj, *obj;
char buf[1024];
REQUIRE(VALID_CONTEXT(ctx)); REQUIRE(VALID_CONTEXT(ctx));
REQUIRE(summary != NULL); REQUIRE(summary != NULL);
REQUIRE(array != NULL); REQUIRE(array != NULL);
json_object *ctxobj, *obj;
char buf[1024];
MCTXLOCK(ctx); MCTXLOCK(ctx);
summary->contextsize += sizeof(*ctx) + summary->contextsize += sizeof(*ctx) +
@@ -2409,11 +2411,11 @@ isc__mem_free(isc_mem_t *mctx, void *ptr FLARG) {
void void
isc__mem_printactive(isc_mem_t *ctx0, FILE *file) { isc__mem_printactive(isc_mem_t *ctx0, FILE *file) {
#if ISC_MEM_TRACKLINES #if ISC_MEM_TRACKLINES
isc__mem_t *ctx = (isc__mem_t *)ctx0; REQUIRE(VALID_CONTEXT(ctx0));
REQUIRE(VALID_CONTEXT(ctx));
REQUIRE(file != NULL); REQUIRE(file != NULL);
isc__mem_t *ctx = (isc__mem_t *)ctx0;
print_active(ctx, file); print_active(ctx, file);
#else #else
UNUSED(ctx0); UNUSED(ctx0);

View File

@@ -14,6 +14,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h>
#include <isc/log.h> #include <isc/log.h>
#include <isc/mem.h> #include <isc/mem.h>
@@ -21,6 +22,7 @@
#include <isc/platform.h> #include <isc/platform.h>
#include <isc/print.h> #include <isc/print.h>
#include <isc/stdio.h> #include <isc/stdio.h>
#include <isc/strerr.h>
#include <isc/string.h> #include <isc/string.h>
#include <isc/thread.h> #include <isc/thread.h>
#include <isc/util.h> #include <isc/util.h>
@@ -151,8 +153,12 @@ pk11_mem_get(size_t size) {
ptr = isc_mem_get(pk11_mctx, size); ptr = isc_mem_get(pk11_mctx, size);
else { else {
ptr = malloc(size); ptr = malloc(size);
if (ptr != NULL) if (ptr == NULL && size != 0) {
allocsize += (int)size; char strbuf[ISC_STRERRORSIZE];
strerror_r(errno, strbuf, sizeof(strbuf));
isc_error_fatal(__FILE__, __LINE__, "malloc failed: %s",
strbuf);
}
} }
UNLOCK(&alloclock); UNLOCK(&alloclock);
@@ -323,8 +329,6 @@ pk11_get_session(pk11_context_t *ctx, pk11_optype_t optype,
UNLOCK(&sessionlock); UNLOCK(&sessionlock);
sp = pk11_mem_get(sizeof(*sp)); sp = pk11_mem_get(sizeof(*sp));
if (sp == NULL)
return (ISC_R_NOMEMORY);
sp->magic = SES_MAGIC; sp->magic = SES_MAGIC;
sp->token = token; sp->token = token;
sp->session = CK_INVALID_HANDLE; sp->session = CK_INVALID_HANDLE;
@@ -479,7 +483,6 @@ scan_slots(void) {
if (slotCount == 0) if (slotCount == 0)
return; return;
slotList = pk11_mem_get(sizeof(CK_SLOT_ID) * slotCount); slotList = pk11_mem_get(sizeof(CK_SLOT_ID) * slotCount);
RUNTIME_CHECK(slotList != NULL);
PK11_FATALCHECK(pkcs_C_GetSlotList, (CK_FALSE, slotList, &slotCount)); PK11_FATALCHECK(pkcs_C_GetSlotList, (CK_FALSE, slotList, &slotCount));
for (i = 0; i < slotCount; i++) { for (i = 0; i < slotCount; i++) {
@@ -490,7 +493,6 @@ scan_slots(void) {
if (rv != CKR_OK) if (rv != CKR_OK)
continue; continue;
token = pk11_mem_get(sizeof(*token)); token = pk11_mem_get(sizeof(*token));
RUNTIME_CHECK(token != NULL);
token->magic = TOK_MAGIC; token->magic = TOK_MAGIC;
token->slotid = slot; token->slotid = slot;
ISC_LINK_INIT(token, link); ISC_LINK_INIT(token, link);

View File

@@ -103,10 +103,10 @@ void isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line);
#if ISC_MUTEX_PROFILE #if ISC_MUTEX_PROFILE
#define isc_mutex_destroy(mp) \ #define isc_mutex_destroy(mp) \
(RUNTIME_CHECK(pthread_mutex_destroy((&(mp)->mutex)) == 0)) RUNTIME_CHECK(pthread_mutex_destroy((&(mp)->mutex)) == 0)
#else #else
#define isc_mutex_destroy(mp) \ #define isc_mutex_destroy(mp) \
(RUNTIME_CHECK(pthread_mutex_destroy((mp)) == 0)) RUNTIME_CHECK(pthread_mutex_destroy((mp)) == 0)
#endif #endif
#if ISC_MUTEX_PROFILE #if ISC_MUTEX_PROFILE

View File

@@ -239,7 +239,11 @@ isc_timer_create(isc_timermgr_t *manager0, isc_timertype_t type,
isc_task_t *task, isc_taskaction_t action, void *arg, isc_task_t *task, isc_taskaction_t action, void *arg,
isc_timer_t **timerp) isc_timer_t **timerp)
{ {
isc__timermgr_t *manager = (isc__timermgr_t *)manager0; REQUIRE(VALID_MANAGER(manager0));
REQUIRE(task != NULL);
REQUIRE(action != NULL);
isc__timermgr_t *manager;
isc__timer_t *timer; isc__timer_t *timer;
isc_result_t result; isc_result_t result;
isc_time_t now; isc_time_t now;
@@ -251,10 +255,7 @@ isc_timer_create(isc_timermgr_t *manager0, isc_timertype_t type,
* called with 'arg' as the arg value. The new timer is returned * called with 'arg' as the arg value. The new timer is returned
* in 'timerp'. * in 'timerp'.
*/ */
manager = (isc__timermgr_t *)manager0;
REQUIRE(VALID_MANAGER(manager));
REQUIRE(task != NULL);
REQUIRE(action != NULL);
if (expires == NULL) if (expires == NULL)
expires = isc_time_epoch; expires = isc_time_epoch;
if (interval == NULL) if (interval == NULL)
@@ -352,7 +353,7 @@ isc_timer_reset(isc_timer_t *timer0, isc_timertype_t type,
const isc_time_t *expires, const isc_interval_t *interval, const isc_time_t *expires, const isc_interval_t *interval,
bool purge) bool purge)
{ {
isc__timer_t *timer = (isc__timer_t *)timer0; isc__timer_t *timer;
isc_time_t now; isc_time_t now;
isc__timermgr_t *manager; isc__timermgr_t *manager;
isc_result_t result; isc_result_t result;
@@ -363,7 +364,8 @@ isc_timer_reset(isc_timer_t *timer0, isc_timertype_t type,
* are purged from its task's event queue. * are purged from its task's event queue.
*/ */
REQUIRE(VALID_TIMER(timer)); REQUIRE(VALID_TIMER(timer0));
timer = (isc__timer_t *)timer0;
manager = timer->manager; manager = timer->manager;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager));
@@ -425,10 +427,11 @@ isc_timer_reset(isc_timer_t *timer0, isc_timertype_t type,
isc_timertype_t isc_timertype_t
isc_timer_gettype(isc_timer_t *timer0) { isc_timer_gettype(isc_timer_t *timer0) {
isc__timer_t *timer = (isc__timer_t *)timer0; isc__timer_t *timer;
isc_timertype_t t; isc_timertype_t t;
REQUIRE(VALID_TIMER(timer)); REQUIRE(VALID_TIMER(timer0));
timer = (isc__timer_t *)timer0;
LOCK(&timer->lock); LOCK(&timer->lock);
t = timer->type; t = timer->type;
@@ -439,7 +442,7 @@ isc_timer_gettype(isc_timer_t *timer0) {
isc_result_t isc_result_t
isc_timer_touch(isc_timer_t *timer0) { isc_timer_touch(isc_timer_t *timer0) {
isc__timer_t *timer = (isc__timer_t *)timer0; isc__timer_t *timer;
isc_result_t result; isc_result_t result;
isc_time_t now; isc_time_t now;
@@ -447,7 +450,8 @@ isc_timer_touch(isc_timer_t *timer0) {
* Set the last-touched time of 'timer' to the current time. * Set the last-touched time of 'timer' to the current time.
*/ */
REQUIRE(VALID_TIMER(timer)); REQUIRE(VALID_TIMER(timer0));
timer = (isc__timer_t *)timer0;
LOCK(&timer->lock); LOCK(&timer->lock);
@@ -470,13 +474,14 @@ isc_timer_touch(isc_timer_t *timer0) {
void void
isc_timer_attach(isc_timer_t *timer0, isc_timer_t **timerp) { isc_timer_attach(isc_timer_t *timer0, isc_timer_t **timerp) {
isc__timer_t *timer = (isc__timer_t *)timer0; isc__timer_t *timer;
/* /*
* Attach *timerp to timer. * Attach *timerp to timer.
*/ */
REQUIRE(VALID_TIMER(timer)); REQUIRE(VALID_TIMER(timer0));
timer = (isc__timer_t *)timer0;
REQUIRE(timerp != NULL && *timerp == NULL); REQUIRE(timerp != NULL && *timerp == NULL);
isc_refcount_increment(&timer->references); isc_refcount_increment(&timer->references);
@@ -661,8 +666,8 @@ static void
set_index(void *what, unsigned int index) { set_index(void *what, unsigned int index) {
isc__timer_t *timer; isc__timer_t *timer;
REQUIRE(VALID_TIMER(what));
timer = what; timer = what;
REQUIRE(VALID_TIMER(timer));
timer->index = index; timer->index = index;
} }
@@ -707,9 +712,10 @@ isc_timermgr_create(isc_mem_t *mctx, isc_timermgr_t **managerp) {
void void
isc_timermgr_poke(isc_timermgr_t *manager0) { isc_timermgr_poke(isc_timermgr_t *manager0) {
isc__timermgr_t *manager = (isc__timermgr_t *)manager0; isc__timermgr_t *manager;
REQUIRE(VALID_MANAGER(manager)); REQUIRE(VALID_MANAGER(manager0));
manager = (isc__timermgr_t *)manager0;
SIGNAL(&manager->wakeup); SIGNAL(&manager->wakeup);
} }

View File

@@ -1,2 +1,3 @@
unmatchedSuppression:* unmatchedSuppression:*
preprocessorErrorDirective:* preprocessorErrorDirective:*
unknownMacro:*