diff --git a/lib/isc/mem.c b/lib/isc/mem.c index cd2066e287..613d4c4d48 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -753,7 +753,6 @@ isc_mem_createx(size_t init_max_size, size_t target_size, isc_mem_t **ctxp, unsigned int flags) { isc__mem_t *ctx; - isc_result_t result; REQUIRE(ctxp != NULL && *ctxp == NULL); REQUIRE(memalloc != NULL); @@ -765,9 +764,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size, RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS); ctx = (memalloc)(arg, sizeof(*ctx)); - if (ctx == NULL) { - return (ISC_R_NOMEMORY); - } + RUNTIME_CHECK(ctx != NULL); if ((flags & ISC_MEMFLAG_NOLOCK) == 0) { isc_mutex_init(&ctx->lock); @@ -816,10 +813,8 @@ isc_mem_createx(size_t init_max_size, size_t target_size, ctx->stats = (memalloc)(arg, (ctx->max_size+1) * sizeof(struct stats)); - if (ctx->stats == NULL) { - result = ISC_R_NOMEMORY; - goto error; - } + RUNTIME_CHECK(ctx->stats != NULL); + memset(ctx->stats, 0, (ctx->max_size + 1) * sizeof(struct stats)); ctx->malloced += (ctx->max_size+1) * sizeof(struct stats); ctx->maxmalloced += (ctx->max_size+1) * sizeof(struct stats); @@ -831,10 +826,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size, ctx->mem_target = target_size; ctx->freelists = (memalloc)(arg, ctx->max_size * sizeof(element *)); - if (ctx->freelists == NULL) { - result = ISC_R_NOMEMORY; - goto error; - } + RUNTIME_CHECK(ctx->freelists != NULL); memset(ctx->freelists, 0, ctx->max_size * sizeof(element *)); ctx->malloced += ctx->max_size * sizeof(element *); @@ -847,10 +839,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size, ctx->debuglist = (memalloc)(arg, (DEBUG_TABLE_COUNT * sizeof(debuglist_t))); - if (ctx->debuglist == NULL) { - result = ISC_R_NOMEMORY; - goto error; - } + RUNTIME_CHECK(ctx->debuglist != NULL); for (i = 0; i < DEBUG_TABLE_COUNT; i++) ISC_LIST_INIT(ctx->debuglist[i]); ctx->malloced += DEBUG_TABLE_COUNT * sizeof(debuglist_t); @@ -867,23 +856,6 @@ isc_mem_createx(size_t init_max_size, size_t target_size, *ctxp = (isc_mem_t *)ctx; return (ISC_R_SUCCESS); - - error: - if (ctx != NULL) { - if (ctx->stats != NULL) - (memfree)(arg, ctx->stats); - if (ctx->freelists != NULL) - (memfree)(arg, ctx->freelists); -#if ISC_MEM_TRACKLINES - if (ctx->debuglist != NULL) - (ctx->memfree)(ctx->arg, ctx->debuglist); -#endif /* ISC_MEM_TRACKLINES */ - if ((ctx->flags & ISC_MEMFLAG_NOLOCK) == 0) - isc_mutex_destroy(&ctx->lock); - (memfree)(arg, ctx); - } - - return (result); } static void @@ -1639,8 +1611,7 @@ isc_mempool_create(isc_mem_t *mctx0, size_t size, isc_mempool_t **mpctxp) { * well, attach to the memory context. */ mpctx = isc_mem_get((isc_mem_t *)mctx, sizeof(isc__mempool_t)); - if (mpctx == NULL) - return (ISC_R_NOMEMORY); + RUNTIME_CHECK(mpctx != NULL); mpctx->common.impmagic = MEMPOOL_MAGIC; mpctx->common.magic = ISCAPI_MPOOL_MAGIC; @@ -2284,16 +2255,10 @@ isc_mem_renderxml(xmlTextWriterPtr writer) { #endif /* HAVE_LIBXML2 */ #ifdef HAVE_JSON -#define CHECKMEM(m) do { \ - if (m == NULL) { \ - result = ISC_R_NOMEMORY;\ - goto error;\ - } \ -} while(0) +#define CHECKMEM(m) RUNTIME_CHECK(m != NULL) static isc_result_t json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array) { - isc_result_t result = ISC_R_FAILURE; json_object *ctxobj, *obj; char buf[1024]; @@ -2385,12 +2350,6 @@ json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array) { MCTXUNLOCK(ctx, &ctx->lock); json_object_array_add(array, ctxobj); return (ISC_R_SUCCESS); - - error: - MCTXUNLOCK(ctx, &ctx->lock); - if (ctxobj != NULL) - json_object_put(ctxobj); - return (result); } isc_result_t