mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 22:45:39 +00:00
Cleanup lib/isc/mem.c after failed allocations made fatal
This commit is contained in:
@@ -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 **ctxp, unsigned int flags)
|
||||||
{
|
{
|
||||||
isc__mem_t *ctx;
|
isc__mem_t *ctx;
|
||||||
isc_result_t result;
|
|
||||||
|
|
||||||
REQUIRE(ctxp != NULL && *ctxp == NULL);
|
REQUIRE(ctxp != NULL && *ctxp == NULL);
|
||||||
REQUIRE(memalloc != 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);
|
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
|
||||||
|
|
||||||
ctx = (memalloc)(arg, sizeof(*ctx));
|
ctx = (memalloc)(arg, sizeof(*ctx));
|
||||||
if (ctx == NULL) {
|
RUNTIME_CHECK(ctx != NULL);
|
||||||
return (ISC_R_NOMEMORY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((flags & ISC_MEMFLAG_NOLOCK) == 0) {
|
if ((flags & ISC_MEMFLAG_NOLOCK) == 0) {
|
||||||
isc_mutex_init(&ctx->lock);
|
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->stats = (memalloc)(arg,
|
||||||
(ctx->max_size+1) * sizeof(struct stats));
|
(ctx->max_size+1) * sizeof(struct stats));
|
||||||
if (ctx->stats == NULL) {
|
RUNTIME_CHECK(ctx->stats != NULL);
|
||||||
result = ISC_R_NOMEMORY;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
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);
|
||||||
ctx->maxmalloced += (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->mem_target = target_size;
|
||||||
ctx->freelists = (memalloc)(arg, ctx->max_size *
|
ctx->freelists = (memalloc)(arg, ctx->max_size *
|
||||||
sizeof(element *));
|
sizeof(element *));
|
||||||
if (ctx->freelists == NULL) {
|
RUNTIME_CHECK(ctx->freelists != NULL);
|
||||||
result = ISC_R_NOMEMORY;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
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 *);
|
||||||
@@ -847,10 +839,7 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
|
|||||||
|
|
||||||
ctx->debuglist = (memalloc)(arg, (DEBUG_TABLE_COUNT *
|
ctx->debuglist = (memalloc)(arg, (DEBUG_TABLE_COUNT *
|
||||||
sizeof(debuglist_t)));
|
sizeof(debuglist_t)));
|
||||||
if (ctx->debuglist == NULL) {
|
RUNTIME_CHECK(ctx->debuglist != NULL);
|
||||||
result = ISC_R_NOMEMORY;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
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);
|
||||||
@@ -867,23 +856,6 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
|
|||||||
*ctxp = (isc_mem_t *)ctx;
|
*ctxp = (isc_mem_t *)ctx;
|
||||||
|
|
||||||
return (ISC_R_SUCCESS);
|
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
|
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.
|
* 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));
|
||||||
if (mpctx == NULL)
|
RUNTIME_CHECK(mpctx != NULL);
|
||||||
return (ISC_R_NOMEMORY);
|
|
||||||
|
|
||||||
mpctx->common.impmagic = MEMPOOL_MAGIC;
|
mpctx->common.impmagic = MEMPOOL_MAGIC;
|
||||||
mpctx->common.magic = ISCAPI_MPOOL_MAGIC;
|
mpctx->common.magic = ISCAPI_MPOOL_MAGIC;
|
||||||
@@ -2284,16 +2255,10 @@ isc_mem_renderxml(xmlTextWriterPtr writer) {
|
|||||||
#endif /* HAVE_LIBXML2 */
|
#endif /* HAVE_LIBXML2 */
|
||||||
|
|
||||||
#ifdef HAVE_JSON
|
#ifdef HAVE_JSON
|
||||||
#define CHECKMEM(m) do { \
|
#define CHECKMEM(m) RUNTIME_CHECK(m != NULL)
|
||||||
if (m == NULL) { \
|
|
||||||
result = ISC_R_NOMEMORY;\
|
|
||||||
goto error;\
|
|
||||||
} \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
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) {
|
||||||
isc_result_t result = ISC_R_FAILURE;
|
|
||||||
json_object *ctxobj, *obj;
|
json_object *ctxobj, *obj;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
@@ -2385,12 +2350,6 @@ json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array) {
|
|||||||
MCTXUNLOCK(ctx, &ctx->lock);
|
MCTXUNLOCK(ctx, &ctx->lock);
|
||||||
json_object_array_add(array, ctxobj);
|
json_object_array_add(array, ctxobj);
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
|
|
||||||
error:
|
|
||||||
MCTXUNLOCK(ctx, &ctx->lock);
|
|
||||||
if (ctxobj != NULL)
|
|
||||||
json_object_put(ctxobj);
|
|
||||||
return (result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
|
Reference in New Issue
Block a user