Skip to content

Commit 5ed1c86

Browse files
committed
Set owner queue to nullptr after commit in scopes
In both WriteScope and ReadScope destructors, set m_owner_queue to nullptr after committing to prevent potential double commits or use-after-free issues.
1 parent 80a25af commit 5ed1c86

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

include/LockFreeSpscQueue.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ class LockFreeSpscQueue
9292

9393
~WriteScope() noexcept
9494
{
95-
if (m_owner_queue != nullptr) { m_owner_queue->commit_write(get_items_written()); }
95+
if (m_owner_queue != nullptr) {
96+
m_owner_queue->commit_write(get_items_written());
97+
m_owner_queue = nullptr;
98+
}
9699
}
97100

98101
// This RAII object is move-only to ensure single ownership of a transaction.
@@ -158,7 +161,10 @@ class LockFreeSpscQueue
158161

159162
~ReadScope() noexcept
160163
{
161-
if (m_owner_queue != nullptr) { m_owner_queue->commit_read(get_items_read()); }
164+
if (m_owner_queue != nullptr) {
165+
m_owner_queue->commit_read(get_items_read());
166+
m_owner_queue = nullptr;
167+
}
162168
}
163169

164170
// This RAII object is move-only to ensure single ownership of a transaction.

0 commit comments

Comments
 (0)