isc_mem_t **ctxp, unsigned int flags)
{
isc__mem_t *ctx;
- isc_result_t result;
REQUIRE(ctxp != NULL && *ctxp == NULL);
REQUIRE(memalloc != NULL);
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);
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);
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 *);
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);
*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
* 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;
#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];
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