mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-02 23:55:27 +00:00
Keep track of the number of times the system malloc() has
failed, to help determine whether a server crash resulted from a bug in the handling of an out-of-memory condition or not.
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: mem.c,v 1.92 2001/06/05 22:14:18 tale Exp $ */
|
/* $Id: mem.c,v 1.93 2001/06/11 20:27:16 gson Exp $ */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
@@ -139,6 +139,8 @@ struct isc_mem {
|
|||||||
#if ISC_MEM_TRACKLINES
|
#if ISC_MEM_TRACKLINES
|
||||||
ISC_LIST(debuglink_t) debuglist;
|
ISC_LIST(debuglink_t) debuglist;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
unsigned int memalloc_failures;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MEMPOOL_MAGIC ISC_MAGIC('M', 'E', 'M', 'p')
|
#define MEMPOOL_MAGIC ISC_MAGIC('M', 'E', 'M', 'p')
|
||||||
@@ -331,8 +333,10 @@ more_basic_blocks(isc_mem_t *ctx) {
|
|||||||
table_size = ctx->basic_table_size + TABLE_INCREMENT;
|
table_size = ctx->basic_table_size + TABLE_INCREMENT;
|
||||||
table = (ctx->memalloc)(ctx->arg,
|
table = (ctx->memalloc)(ctx->arg,
|
||||||
table_size * sizeof (unsigned char *));
|
table_size * sizeof (unsigned char *));
|
||||||
if (table == NULL)
|
if (table == NULL) {
|
||||||
|
ctx->memalloc_failures++;
|
||||||
return (ISC_FALSE);
|
return (ISC_FALSE);
|
||||||
|
}
|
||||||
if (ctx->basic_table_size != 0) {
|
if (ctx->basic_table_size != 0) {
|
||||||
memcpy(table, ctx->basic_table,
|
memcpy(table, ctx->basic_table,
|
||||||
ctx->basic_table_size *
|
ctx->basic_table_size *
|
||||||
@@ -344,8 +348,10 @@ more_basic_blocks(isc_mem_t *ctx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
new = (ctx->memalloc)(ctx->arg, NUM_BASIC_BLOCKS * ctx->mem_target);
|
new = (ctx->memalloc)(ctx->arg, NUM_BASIC_BLOCKS * ctx->mem_target);
|
||||||
if (new == NULL)
|
if (new == NULL) {
|
||||||
|
ctx->memalloc_failures++;
|
||||||
return (ISC_FALSE);
|
return (ISC_FALSE);
|
||||||
|
}
|
||||||
ctx->total += increment;
|
ctx->total += increment;
|
||||||
ctx->basic_table[ctx->basic_table_count] = new;
|
ctx->basic_table[ctx->basic_table_count] = new;
|
||||||
ctx->basic_table_count++;
|
ctx->basic_table_count++;
|
||||||
@@ -449,19 +455,20 @@ mem_getunlocked(isc_mem_t *ctx, size_t size) {
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
ret = (ctx->memalloc)(ctx->arg, size);
|
ret = (ctx->memalloc)(ctx->arg, size);
|
||||||
if (ret != NULL) {
|
if (ret == NULL) {
|
||||||
ctx->total += size;
|
ctx->memalloc_failures++;
|
||||||
ctx->inuse += size;
|
goto done;
|
||||||
ctx->stats[ctx->max_size].gets++;
|
|
||||||
ctx->stats[ctx->max_size].totalgets++;
|
|
||||||
/*
|
|
||||||
* If we don't set new_size to size, then the
|
|
||||||
* ISC_MEM_FILL code might write over bytes we
|
|
||||||
* don't own.
|
|
||||||
*/
|
|
||||||
new_size = size;
|
|
||||||
}
|
}
|
||||||
goto done;
|
ctx->total += size;
|
||||||
|
ctx->inuse += size;
|
||||||
|
ctx->stats[ctx->max_size].gets++;
|
||||||
|
ctx->stats[ctx->max_size].totalgets++;
|
||||||
|
/*
|
||||||
|
* If we don't set new_size to size, then the
|
||||||
|
* ISC_MEM_FILL code might write over bytes we
|
||||||
|
* don't own.
|
||||||
|
*/
|
||||||
|
new_size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -573,6 +580,8 @@ mem_get(isc_mem_t *ctx, size_t size) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = (ctx->memalloc)(ctx->arg, size);
|
ret = (ctx->memalloc)(ctx->arg, size);
|
||||||
|
if (ret == NULL)
|
||||||
|
ctx->memalloc_failures++;
|
||||||
|
|
||||||
#if ISC_MEM_FILL
|
#if ISC_MEM_FILL
|
||||||
if (ret != NULL)
|
if (ret != NULL)
|
||||||
@@ -750,6 +759,8 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
|
|||||||
ISC_LIST_INIT(ctx->debuglist);
|
ISC_LIST_INIT(ctx->debuglist);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ctx->memalloc_failures = 0;
|
||||||
|
|
||||||
*ctxp = ctx;
|
*ctxp = ctx;
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user