[dovecot-cvs] dovecot/src/lib data-stack.c, 1.26, 1.27 data-stack.h, 1.7, 1.8
tss at dovecot.org
tss at dovecot.org
Sun Mar 18 05:09:38 EET 2007
Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv10272/lib
Modified Files:
data-stack.c data-stack.h
Log Message:
Added data_stack_set_clean_after_pop()
Index: data-stack.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/data-stack.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- data-stack.c 10 Sep 2006 17:59:58 -0000 1.26
+++ data-stack.c 18 Mar 2007 03:09:36 -0000 1.27
@@ -29,7 +29,7 @@
#ifdef DEBUG
# define CLEAR_CHR 0xde
-#elif defined(USE_GC)
+#else
# define CLEAR_CHR 0
#endif
@@ -69,6 +69,7 @@
static struct stack_block *last_buffer_block;
static size_t last_buffer_size;
+static bool clean_after_pop = FALSE;
unsigned int t_push(void)
{
@@ -114,7 +115,6 @@
return data_stack_frame++;
}
-#ifndef USE_GC
static void free_blocks(struct stack_block *block)
{
struct stack_block *next;
@@ -125,16 +125,27 @@
next = block->next;
if (unused_block == NULL || block->size > unused_block->size) {
+ if (clean_after_pop) {
+ memset(STACK_BLOCK_DATA(unused_block),
+ CLEAR_CHR, unused_block->size);
+ }
+#ifndef USE_GC
free(unused_block);
+#endif
unused_block = block;
} else {
+ if (clean_after_pop) {
+ memset(STACK_BLOCK_DATA(block), CLEAR_CHR,
+ block->size);
+ }
+#ifndef USE_GC
free(block);
+#endif
}
block = next;
}
}
-#endif
unsigned int t_pop(void)
{
@@ -147,16 +158,14 @@
/* update the current block */
current_block = current_frame_block->block[frame_pos];
current_block->left = current_frame_block->block_space_used[frame_pos];
-#ifdef CLEAR_CHR
- memset(STACK_BLOCK_DATA(current_block) +
- (current_block->size - current_block->left), CLEAR_CHR,
- current_block->left);
-#endif
+ if (clean_after_pop) {
+ memset(STACK_BLOCK_DATA(current_block) +
+ (current_block->size - current_block->left), CLEAR_CHR,
+ current_block->left);
+ }
if (current_block->next != NULL) {
/* free unused blocks */
-#ifndef USE_GC
free_blocks(current_block->next);
-#endif
current_block->next = NULL;
}
@@ -351,6 +360,11 @@
t_malloc_real(size, TRUE);
}
+void data_stack_set_clean_after_pop(bool enable)
+{
+ clean_after_pop = enable;
+}
+
void data_stack_init(void)
{
if (data_stack_frame == 0) {
@@ -531,6 +545,9 @@
current_frame = NULL;
buffer_mem = NULL;
+#ifdef DEBUG
+ clean_after_pop = TRUE;
+#endif
t_push();
}
Index: data-stack.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/data-stack.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- data-stack.h 1 Nov 2006 19:19:35 -0000 1.7
+++ data-stack.h 18 Mar 2007 03:09:36 -0000 1.8
@@ -90,6 +90,9 @@
t_buffer_alloc(sizeof(type) * (size))
void t_buffer_alloc(size_t size);
+/* If enabled, all the used memory is cleared after t_pop(). */
+void data_stack_set_clean_after_pop(bool enable);
+
void data_stack_init(void);
void data_stack_deinit(void);
More information about the dovecot-cvs
mailing list