dovecot: If we fail with out of memory, make sure i_panic() can ...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Dec 5 17:47:52 EET 2007
details: http://hg.dovecot.org/dovecot/rev/f6118fc9c23e
changeset: 6934:f6118fc9c23e
user: Timo Sirainen <tss at iki.fi>
date: Wed Dec 05 17:09:07 2007 +0200
description:
If we fail with out of memory, make sure i_panic() can allocate enough
memory for itself.
diffstat:
1 file changed, 15 insertions(+)
src/lib/data-stack.c | 15 +++++++++++++++
diffs (39 lines):
diff -r ad16a4582033 -r f6118fc9c23e src/lib/data-stack.c
--- a/src/lib/data-stack.c Wed Dec 05 17:06:37 2007 +0200
+++ b/src/lib/data-stack.c Wed Dec 05 17:09:07 2007 +0200
@@ -70,6 +70,12 @@ static struct stack_block *last_buffer_b
static struct stack_block *last_buffer_block;
static size_t last_buffer_size;
static bool clean_after_pop = FALSE;
+static bool outofmem = FALSE;
+
+union {
+ struct stack_block block;
+ unsigned char data[128];
+} outofmem_area;
unsigned int t_push(void)
{
@@ -200,6 +206,12 @@ static struct stack_block *mem_block_all
block = GC_malloc(SIZEOF_MEMBLOCK + alloc_size);
#endif
if (unlikely(block == NULL)) {
+ if (outofmem) {
+ if (min_size > outofmem_area.block.left)
+ abort();
+ return &outofmem_area.block;
+ }
+ outofmem = TRUE;
i_panic("data stack: Out of memory when allocating %"
PRIuSIZE_T" bytes", alloc_size + SIZEOF_MEMBLOCK);
}
@@ -369,6 +381,9 @@ void data_stack_init(void)
if (data_stack_frame == 0) {
data_stack_frame = 1;
+ outofmem_area.block.size = outofmem_area.block.left =
+ sizeof(outofmem_area) - sizeof(outofmem_area.block);
+
current_block = mem_block_alloc(INITIAL_STACK_SIZE);
current_block->left = current_block->size;
current_block->next = NULL;
More information about the dovecot-cvs
mailing list