commit 6066fe800542ac9758b497ae62e6ae27e00ffe08
parent 89fb98b5ec4ee9f5276f5369ab4efa5c01f864f1
Author: Jan Varga <Jan.Varga@gmail.com>
Date: Tue, 21 Oct 2025 20:41:43 +0000
Bug 1995516 - Move forwarded callback outside page loop in Queue::Iterate; r=xpcom-reviewers,jstutte
std::forward should only be used once per parameter. In the page iteration loop,
the forwarded callback was potentially moved multiple times. Move the callback
into a local variable before entering the loop, and update internal
IterateOverPage to accept it by reference instead of forwarding reference.
Differential Revision: https://phabricator.services.mozilla.com/D269381
Diffstat:
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/xpcom/threads/Queue.h b/xpcom/threads/Queue.h
@@ -189,12 +189,13 @@ class Queue {
return;
}
+ std::decay_t<Callback> callback = std::forward<Callback>(aCallback);
+
uint16_t start = mOffsetHead;
uint32_t count = mCount;
uint16_t countInPage = mHeadLength;
for (Page* page = mHead; page != nullptr; page = page->mNext) {
- IterateOverPage(page, start, countInPage,
- std::forward<Callback>(aCallback));
+ IterateOverPage(page, start, countInPage, callback);
start = 0;
count -= countInPage;
countInPage = std::min(count, static_cast<uint32_t>(ItemsPerPage));
@@ -226,7 +227,7 @@ class Queue {
template <typename Callback>
void IterateOverPage(Page* aPage, size_t aOffsetStart, size_t aCount,
- Callback&& aCallback) {
+ Callback& aCallback) {
size_t aOffsetEnd = aOffsetStart + aCount;
MOZ_ASSERT(aCount <= ItemsPerPage);
MOZ_ASSERT(aOffsetEnd > aOffsetStart);