dovecot-2.2: lib: data-stack - add DEBUG size and sentry updatin...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jul 28 13:54:29 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/e33102604242
changeset: 17652:e33102604242
user:      Phil Carmody <phil at dovecot.fi>
date:      Mon Jul 28 16:45:33 2014 +0300
description:
lib: data-stack - add DEBUG size and sentry updating to t_try_realloc
Without this, t_pop() will report errors.

Signed-off-by: Phil Carmody <phil at dovecot.fi>

diffstat:

 src/lib/data-stack.c |  17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)

diffs (34 lines):

diff -r 5d290af2d1da -r e33102604242 src/lib/data-stack.c
--- a/src/lib/data-stack.c	Mon Jul 28 16:45:33 2014 +0300
+++ b/src/lib/data-stack.c	Mon Jul 28 16:45:33 2014 +0300
@@ -474,6 +474,15 @@
 
 		new_alloc_size = ALLOC_SIZE(size);
 		alloc_growth = (new_alloc_size - last_alloc_size);
+#ifdef DEBUG
+		size_t old_raw_size; /* sorry, non-C99 users - add braces if you need them */
+		old_raw_size = *(size_t *)PTR_OFFSET(mem, -MEM_ALIGN(sizeof(size_t)));
+		i_assert(ALLOC_SIZE(old_raw_size) == last_alloc_size);
+		/* Only check one byte for over-run, that catches most
+		   offenders who are likely to use t_try_realloc() */
+		i_assert(((unsigned char*)mem)[old_raw_size] == CLEAR_CHR);
+#endif
+
 		if (current_block->left >= alloc_growth) {
 			/* just shrink the available size */
 			current_block->left -= alloc_growth;
@@ -481,6 +490,14 @@
 				current_block->lowwater = current_block->left;
 			current_frame_block->last_alloc_size[frame_pos] =
 				new_alloc_size;
+#ifdef DEBUG
+			/* All reallocs are permanent by definition
+			   However, they don't count as a new allocation */
+			current_frame_block->alloc_bytes[frame_pos] += alloc_growth;
+			*(size_t *)PTR_OFFSET(mem, -MEM_ALIGN(sizeof(size_t))) = size;
+			memset(PTR_OFFSET(mem, size), CLEAR_CHR,
+			       new_alloc_size - size - MEM_ALIGN(sizeof(size_t)));
+#endif
 			return TRUE;
 		}
 	}


More information about the dovecot-cvs mailing list