Commit 509ef0c8 authored by Andreas Gustafsson's avatar Andreas Gustafsson
Browse files

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.
parent 8de7014e
......@@ -15,7 +15,7 @@
* 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>
......@@ -139,6 +139,8 @@ struct isc_mem {
#if ISC_MEM_TRACKLINES
ISC_LIST(debuglink_t) debuglist;
#endif
unsigned int memalloc_failures;
};
#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 = (ctx->memalloc)(ctx->arg,
table_size * sizeof (unsigned char *));
if (table == NULL)
if (table == NULL) {
ctx->memalloc_failures++;
return (ISC_FALSE);
}
if (ctx->basic_table_size != 0) {
memcpy(table, ctx->basic_table,
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);
if (new == NULL)
if (new == NULL) {
ctx->memalloc_failures++;
return (ISC_FALSE);
}
ctx->total += increment;
ctx->basic_table[ctx->basic_table_count] = new;
ctx->basic_table_count++;
......@@ -449,19 +455,20 @@ mem_getunlocked(isc_mem_t *ctx, size_t size) {
goto done;
}
ret = (ctx->memalloc)(ctx->arg, size);
if (ret != NULL) {
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;
if (ret == NULL) {
ctx->memalloc_failures++;
goto done;
}
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
ret = (ctx->memalloc)(ctx->arg, size);
if (ret == NULL)
ctx->memalloc_failures++;
#if ISC_MEM_FILL
if (ret != NULL)
......@@ -750,6 +759,8 @@ isc_mem_createx(size_t init_max_size, size_t target_size,
ISC_LIST_INIT(ctx->debuglist);
#endif
ctx->memalloc_failures = 0;
*ctxp = ctx;
return (ISC_R_SUCCESS);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment