dovecot-1.1: mempool system clean: Don't break if realloc() shri...
dovecot at dovecot.org
dovecot at dovecot.org
Fri Jan 16 04:36:34 EET 2009
details: http://hg.dovecot.org/dovecot-1.1/rev/17c73b14ed9d
changeset: 8103:17c73b14ed9d
user: Timo Sirainen <tss at iki.fi>
date: Thu Jan 15 21:36:26 2009 -0500
description:
mempool system clean: Don't break if realloc() shrinks the memory area.
diffstat:
1 file changed, 4 insertions(+), 2 deletions(-)
src/lib/mempool-system-clean.c | 6 ++++--
diffs (29 lines):
diff -r 8b49675e1641 -r 17c73b14ed9d src/lib/mempool-system-clean.c
--- a/src/lib/mempool-system-clean.c Thu Jan 15 17:21:01 2009 -0500
+++ b/src/lib/mempool-system-clean.c Thu Jan 15 21:36:26 2009 -0500
@@ -136,6 +136,7 @@ static void *pool_system_clean_realloc(p
size_t old_size, size_t new_size)
{
void *new_mem;
+ size_t old_alloc_size;
if (unlikely(new_size == 0 || new_size > SSIZE_T_MAX))
i_panic("Trying to allocate %"PRIuSIZE_T" bytes", new_size);
@@ -146,14 +147,15 @@ static void *pool_system_clean_realloc(p
i_assert(old_size == (size_t)-1 ||
old_size <= malloc_usable_size(mem));
#endif
- memcpy(new_mem, mem, mem_get_size(mem));
- pool_system_clean_free(pool, mem);
+ old_alloc_size = mem_get_size(mem);
+ memcpy(new_mem, mem, I_MIN(old_alloc_size, new_size));
if (old_size < new_size) {
/* clear new data */
memset((char *)new_mem + old_size, 0,
new_size - old_size);
}
+ pool_system_clean_free(pool, mem);
}
return new_mem;
More information about the dovecot-cvs
mailing list