diff --git a/ChangeLog b/ChangeLog index 5dfe6ec781..c815eafd25 100644 --- a/ChangeLog +++ b/ChangeLog @@ -52,6 +52,8 @@ Changes in version 0.2.1.3-alpha - 2008-07-xx HiddenServiceExcludeNodes as obsolete: they never worked properly, and nobody claims to be using them. Fixes bug 754. Bugfix on 0.1.0.1-rc. Patch from Christian Wilms. + - Fix a small alignment and memory-wasting bug on buffer chunks. Spotted + by rovv. o Minor bugfixes (controller): - When closing an application-side connection because its circuit diff --git a/src/or/buffers.c b/src/or/buffers.c index 17bd85eeae..d013ce2ffb 100644 --- a/src/or/buffers.c +++ b/src/or/buffers.c @@ -69,12 +69,14 @@ typedef struct chunk_t { * more than one byte long. */ } chunk_t; +#define CHUNK_HEADER_LEN STRUCT_OFFSET(chunk_t, mem[0]) + /** Return the number of bytes needed to allocate a chunk to hold * memlen bytes. */ -#define CHUNK_ALLOC_SIZE(memlen) (sizeof(chunk_t) + (memlen) - 1) +#define CHUNK_ALLOC_SIZE(memlen) (CHUNK_HEADER_LEN + (memlen)) /** Return the number of usable bytes in a chunk allocated with * malloc(memlen). */ -#define CHUNK_SIZE_WITH_ALLOC(memlen) ((memlen) - sizeof(chunk_t) + 1) +#define CHUNK_SIZE_WITH_ALLOC(memlen) ((memlen) - CHUNK_HEADER_LEN) /** Return the next character in chunk onto which data can be appended. * If the chunk is full, this might be off the end of chunk->mem. */