Skip to content

Commit f882c8f

Browse files
Rob Lyerlymeta-codesync[bot]
authored andcommitted
Don't directly invoke handle destructors in RAMCacheComponent
Summary: It's undefined behavior to call an item's destructor twice (see [this comment](https://www.internalfb.com/diff/D88516565?dst_version_fbid=1376806097214701&transaction_fbid=1562143038240295)), moving the handle out into a temporary is the more idiomatic way to destroy the rvalue ref argument. Reviewed By: AlnisM Differential Revision: D90253324 fbshipit-source-id: 6e1d9797ef9532746c35e3c9bdc7feb1cea1c36a
1 parent 91699ce commit f882c8f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

cachelib/interface/components/RAMCacheComponent.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ folly::coro::Task<UnitResult> RAMCacheComponent::insert(
186186
co_return makeError(Error::Code::INSERT_FAILED, e.what());
187187
}
188188

189-
handle.~AllocatedHandle();
189+
auto _ = std::move(handle);
190190
co_return folly::unit;
191191
}
192192

@@ -215,7 +215,7 @@ RAMCacheComponent::insertOrReplace(AllocatedHandle&& handle) {
215215
co_return makeError(Error::Code::INSERT_FAILED, e.what());
216216
}
217217

218-
handle.~AllocatedHandle();
218+
auto _ = std::move(handle);
219219
if (replacedHandle) {
220220
co_return toGenericHandle<AllocatedHandle>(*this, replacedHandle);
221221
} else {
@@ -261,7 +261,7 @@ folly::coro::Task<UnitResult> RAMCacheComponent::remove(ReadHandle&& handle) {
261261
co_return makeError(Error::Code::REMOVE_FAILED, e.what());
262262
}
263263

264-
handle.~ReadHandle();
264+
auto _ = std::move(handle);
265265
co_return folly::unit;
266266
}
267267

0 commit comments

Comments
 (0)