Mercurial > dovecot > original-hg > dovecot-1.2
changeset 7027:ae06eb5e2638 HEAD
Removed DISABLE_DATA_STACK. Using it was probably broken anyway and it was
confusing having two implementations in the same file.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 22 Dec 2007 03:05:29 +0200 |
parents | 8dc08ad6717c |
children | 78a75a5a5350 |
files | src/lib/data-stack.c src/lib/data-stack.h |
diffstat | 2 files changed, 3 insertions(+), 163 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/data-stack.c Sat Dec 22 03:01:35 2007 +0200 +++ b/src/lib/data-stack.c Sat Dec 22 03:05:29 2007 +0200 @@ -13,12 +13,6 @@ # include <gc.h> #endif -/* Use malloc() and free() for all memory allocations. Useful for debugging - memory corruption. */ -/* #define DISABLE_DATA_STACK */ - -#ifndef DISABLE_DATA_STACK - /* Initial stack size - this should be kept in a size that doesn't exceed in a normal use to avoid extra malloc()ing. */ #ifdef DEBUG @@ -494,156 +488,3 @@ current_block = NULL; unused_block = NULL; } - -#else - -#ifdef USE_GC -# error No GC with disabled data stack -#endif - -struct stack_frame { - struct stack_frame *next; - struct frame_alloc *allocs; -}; - -struct frame_alloc { - struct frame_alloc *next; - void *mem; -}; - -unsigned int data_stack_frame; - -static struct stack_frame *current_frame; -static void *buffer_mem; - -unsigned int t_push(void) -{ - struct stack_frame *frame; - - frame = malloc(sizeof(struct stack_frame)); - if (frame == NULL) - i_panic("t_push(): Out of memory"); - frame->allocs = NULL; - - frame->next = current_frame; - current_frame = frame; - return data_stack_frame++; -} - -unsigned int t_pop(void) -{ - struct stack_frame *frame; - struct frame_alloc *alloc; - - frame = current_frame; - current_frame = frame->next; - - while (frame->allocs != NULL) { - alloc = frame->allocs; - frame->allocs = alloc->next; - - free(alloc->mem); - free(alloc); - } - - free(frame); - return --data_stack_frame; -} - -static void add_alloc(void *mem) -{ - struct frame_alloc *alloc; - - alloc = malloc(sizeof(struct frame_alloc)); - if (alloc == NULL) - i_panic("add_alloc(): Out of memory"); - alloc->mem = mem; - alloc->next = current_frame->allocs; - current_frame->allocs = alloc; - - if (buffer_mem != NULL) { - free(buffer_mem); - buffer_mem = NULL; - } -} - -void *t_malloc(size_t size) -{ - void *mem; - - mem = malloc(size); - if (mem == NULL) - i_panic("t_malloc(): Out of memory"); - add_alloc(mem); - return mem; -} - -void *t_malloc0(size_t size) -{ - void *mem; - - mem = calloc(size, 1); - if (mem == NULL) - i_panic("t_malloc0(): Out of memory"); - add_alloc(mem); - return mem; -} - -bool t_try_realloc(void *mem ATTR_UNUSED, size_t size ATTR_UNUSED) -{ - return FALSE; -} - -void *t_buffer_get(size_t size) -{ - buffer_mem = realloc(buffer_mem, size); - if (buffer_mem == NULL) - i_panic("t_buffer_get(): Out of memory"); - return buffer_mem; -} - -void *t_buffer_reget(void *buffer, size_t size) -{ - i_assert(buffer == buffer_mem); - - buffer_mem = realloc(buffer_mem, size); - if (buffer_mem == NULL) - i_panic("t_buffer_reget(): Out of memory"); - return buffer_mem; -} - -void t_buffer_alloc(size_t size) -{ - void *mem; - - i_assert(buffer_mem != NULL); - - mem = realloc(buffer_mem, size); - if (mem == NULL) - i_panic("t_buffer_alloc(): Out of memory"); - buffer_mem = NULL; - - add_alloc(mem); -} - -void data_stack_init(void) -{ - data_stack_frame = 0; - current_frame = NULL; - buffer_mem = NULL; - -#ifdef DEBUG - clean_after_pop = TRUE; -#endif - t_push(); -} - -void data_stack_deinit(void) -{ - t_pop(); - - if (data_stack_frame != 0) - i_panic("Missing t_pop() call"); -} - -#endif
--- a/src/lib/data-stack.h Sat Dec 22 03:01:35 2007 +0200 +++ b/src/lib/data-stack.h Sat Dec 22 03:05:29 2007 +0200 @@ -26,10 +26,9 @@ - t_malloc()ed data could be accidentally stored into permanent location and accessed after it's already been freed. const'ing the return values helps for most uses though (see the t_malloc() description). - - Debugging invalid memory usage requires recompilation with - -DDISABLE_DATA_STACK which then uses malloc() and free() for all - allocations and keeping track of them for stack frames making it much - slower. + - Debugging invalid memory usage may be difficult using existing tools, + although compiling with DEBUG enabled helps finding simple buffer + overflows. */ extern unsigned int data_stack_frame;