Skip to content

Commit 336cf2a

Browse files
AlnisMmeta-codesync[bot]
authored andcommitted
Fix use-after-free in moveForSlabRelease fragmentation stats
Summary: `moveForSlabRelease` called `util::getFragmentation(*this, oldItem)` after `allocator_->free(&oldItem)`, accessing freed memory (`getSize()`, `isChainedItem()`, `getKey()`). Move the fragmentation computation before the `free()` call to eliminate the use-after-free. Reviewed By: rlyerly Differential Revision: D98666914 fbshipit-source-id: 427d5a8e460d22a3d13e4941401d7dd8b60bd3a9
1 parent 55626f7 commit 336cf2a

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

cachelib/allocator/CacheAllocator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5246,10 +5246,9 @@ bool CacheAllocator<CacheTrait>::moveForSlabRelease(Item& oldItem) {
52465246
auto ref = unmarkMovingAndWakeUpWaiters(oldItem, std::move(newItemHdl));
52475247
XDCHECK_EQ(0u, ref);
52485248
}
5249-
allocator_->free(&oldItem);
5250-
52515249
(*stats_.fragmentationSize)[allocInfo.poolId][allocInfo.classId].sub(
52525250
util::getFragmentation(*this, oldItem));
5251+
allocator_->free(&oldItem);
52535252
stats_.numMoveSuccesses.inc();
52545253
return true;
52555254
}

0 commit comments

Comments
 (0)