/** Helper: allocate a new memarea chunk of around <b>chunk_size</b> bytes. */ static memarea_chunk_t * alloc_chunk(size_t sz, int freelist_ok) { if (freelist && freelist_ok) { memarea_chunk_t *res = freelist; freelist = res->next_chunk; res->next_chunk = NULL; --freelist_len; CHECK_SENTINEL(res); return res; } else { size_t chunk_size = freelist_ok ? CHUNK_SIZE : sz; memarea_chunk_t *res; chunk_size += SENTINEL_LEN; res = tor_malloc_roundup(&chunk_size); res->next_chunk = NULL; res->mem_size = chunk_size - CHUNK_HEADER_SIZE - SENTINEL_LEN; res->next_mem = res->u.mem; tor_assert(res->next_mem+res->mem_size+SENTINEL_LEN == ((char*)res)+chunk_size); tor_assert(realign_pointer(res->next_mem) == res->next_mem); SET_SENTINEL(res); return res; } }
/** Helper: allocate a new memarea chunk of around <b>chunk_size</b> bytes. */ static memarea_chunk_t * alloc_chunk(size_t sz, int freelist_ok) { tor_assert(sz < SIZE_T_CEILING); if (freelist && freelist_ok) { memarea_chunk_t *res = freelist; freelist = res->next_chunk; res->next_chunk = NULL; --freelist_len; return res; } else { size_t chunk_size = freelist_ok ? CHUNK_SIZE : sz; memarea_chunk_t *res = tor_malloc_roundup(&chunk_size); res->next_chunk = NULL; res->mem_size = chunk_size - CHUNK_HEADER_SIZE; res->next_mem = res->u.mem; tor_assert(res->next_mem+res->mem_size == ((char*)res)+chunk_size); tor_assert(realign_pointer(res->next_mem) == res->next_mem); return res; } }