Skip to content

Commit b9408d7

Browse files
committed
Fix/simplify chunk_recycle() allocation size computations.
Remove outer CHUNK_CEILING(s2u(...)) from alloc_size computation, since s2u() may overflow (and return 0), and CHUNK_CEILING() is only needed around the alignment portion of the computation. This fixes a regression caused by 5707d6f (Quantize szad trees by size class.) and first released in 4.0.0. This resolves jemalloc#497.
1 parent 2cdf07a commit b9408d7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/chunk.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,18 @@ chunk_recycle(tsdn_t *tsdn, arena_t *arena, chunk_hooks_t *chunk_hooks,
209209
size_t alloc_size, leadsize, trailsize;
210210
bool zeroed, committed;
211211

212+
assert(CHUNK_CEILING(size) == size);
213+
assert(alignment > 0);
212214
assert(new_addr == NULL || alignment == chunksize);
215+
assert(CHUNK_ADDR2BASE(new_addr) == new_addr);
213216
/*
214217
* Cached chunks use the node linkage embedded in their headers, in
215218
* which case dalloc_node is true, and new_addr is non-NULL because
216219
* we're operating on a specific chunk.
217220
*/
218221
assert(dalloc_node || new_addr != NULL);
219222

220-
alloc_size = CHUNK_CEILING(s2u(size + alignment - chunksize));
223+
alloc_size = size + CHUNK_CEILING(alignment) - chunksize;
221224
/* Beware size_t wrap-around. */
222225
if (alloc_size < size)
223226
return (NULL);

0 commit comments

Comments
 (0)