diff --git a/configure.in b/configure.in
index 7432fa97a6..1497813985 100644
--- a/configure.in
+++ b/configure.in
@@ -171,7 +171,7 @@ dnl -------------------------------------------------------------------
dnl Check for functions before libevent, since libevent-1.2 apparently
dnl exports strlcpy without defining it in a header.
-AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull ftello getaddrinfo localtime_r gmtime_r memmem strtok_r inet_pton inet_ntop mallinfo)
+AC_CHECK_FUNCS(gettimeofday ftime socketpair uname inet_aton strptime getrlimit strlcat strlcpy strtoull ftello getaddrinfo localtime_r gmtime_r memmem strtok_r inet_pton inet_ntop mallinfo malloc_good_size malloc_usable_size)
if test "$enable_threads" = "yes"; then
AC_CHECK_HEADERS(pthread.h)
@@ -266,7 +266,7 @@ AC_CHECK_HEADERS(netdb.h sys/ioctl.h sys/socket.h arpa/inet.h netinet/in.h pwd.h
dnl These headers are not essential
-AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/param.h sys/wait.h limits.h sys/limits.h netinet/in.h arpa/inet.h machine/limits.h syslog.h sys/time.h sys/resource.h inttypes.h utime.h sys/utime.h sys/mman.h netintet/in.h netinet/in6.h malloc.h sys/syslimits.h)
+AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/param.h sys/wait.h limits.h sys/limits.h netinet/in.h arpa/inet.h machine/limits.h syslog.h sys/time.h sys/resource.h inttypes.h utime.h sys/utime.h sys/mman.h netintet/in.h netinet/in6.h malloc.h sys/syslimits.h malloc/malloc.h)
AC_CHECK_HEADERS(net/if.h, net_if_found=1, net_if_found=0,
[#ifdef HAVE_SYS_TYPES_H
diff --git a/src/common/mempool.c b/src/common/mempool.c
index 142ba0b9ae..36eb0e545f 100644
--- a/src/common/mempool.c
+++ b/src/common/mempool.c
@@ -78,6 +78,7 @@
#define ASSERT(x) tor_assert(x)
#undef ALLOC_CAN_RETURN_NULL
#define TOR
+//#define ALLOC_ROUNDUP(p) tor_malloc_roundup(p)
/* End Tor dependencies */
#else
/* If you're not building this as part of Tor, you'll want to define the
@@ -172,12 +173,22 @@ static mp_chunk_t *
mp_chunk_new(mp_pool_t *pool)
{
size_t sz = pool->new_chunk_capacity * pool->item_alloc_size;
+#ifdef ALLOC_ROUNDUP
+ size_t alloc_size = CHUNK_OVERHEAD + sz;
+ mp_chunk_t *chunk = ALLOC_ROUNDUP(&alloc_size);
+#else
mp_chunk_t *chunk = ALLOC(CHUNK_OVERHEAD + sz);
+#endif
CHECK_ALLOC(chunk);
memset(chunk, 0, sizeof(mp_chunk_t)); /* Doesn't clear the whole thing. */
chunk->magic = MP_CHUNK_MAGIC;
+#ifdef ALLOC_ROUNDUP
+ chunk->mem_size = alloc_size - CHUNK_OVERHEAD;
+ chunk->capacity = chunk->mem_size / pool->item_alloc_size;
+#else
chunk->capacity = pool->new_chunk_capacity;
chunk->mem_size = sz;
+#endif
chunk->next_mem = chunk->mem;
chunk->pool = pool;
return chunk;
diff --git a/src/common/util.c b/src/common/util.c
index 91f588ba47..d11b508b92 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -69,7 +69,10 @@ const char util_c_id[] = "$Id$";
#ifdef HAVE_TIME_H
#include