# HG changeset patch # User Timo Sirainen # Date 1187274191 -10800 # Node ID 7d82a232b5b0e4dd8d4281579b55c2650e6c27bb # Parent 6342c8cc76c79457ffa48cfd846e4cf281d25d70 pool_system_realloc(): Moved malloc_usable_size() check before realloc() so that we don't assert-crash if realloc() shrinks memory. diff -r 6342c8cc76c7 -r 7d82a232b5b0 src/lib/mempool-system.c --- a/src/lib/mempool-system.c Wed Aug 15 19:17:48 2007 +0300 +++ b/src/lib/mempool-system.c Thu Aug 16 17:23:11 2007 +0300 @@ -97,6 +97,11 @@ if (new_size == 0 || new_size > SSIZE_T_MAX) i_panic("Trying to allocate %"PRIuSIZE_T" bytes", new_size); +#if !defined(USE_GC) && defined(HAVE_MALLOC_USABLE_SIZE) + i_assert(old_size == (size_t)-1 || mem == NULL || + old_size <= malloc_usable_size(mem)); +#endif + #ifndef USE_GC mem = realloc(mem, new_size); #else @@ -107,10 +112,6 @@ "pool_system_realloc(): Out of memory"); } -#if !defined(USE_GC) && defined(HAVE_MALLOC_USABLE_SIZE) - i_assert(old_size == (size_t)-1 || mem == NULL || - old_size <= malloc_usable_size(mem)); -#endif if (old_size < new_size) { /* clear new data */ memset((char *) mem + old_size, 0, new_size - old_size);