Skip to content

Commit 6b73369

Browse files
l0rincryanofsky
andcommitted
coins, refactor: Assume state after SetClean in AddFlags to prevent dangling pointers
Co-authored-by: Ryan Ofsky <[email protected]>
1 parent fc8c282 commit 6b73369

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/coins.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,13 @@ struct CCoinsCacheEntry
166166
{
167167
Assume(flags & (DIRTY | FRESH));
168168
if (!pair.second.m_flags) {
169+
Assume(!pair.second.m_prev && !pair.second.m_next);
169170
pair.second.m_prev = sentinel.second.m_prev;
170171
pair.second.m_next = &sentinel;
171172
sentinel.second.m_prev = &pair;
172173
pair.second.m_prev->second.m_next = &pair;
173174
}
175+
Assume(pair.second.m_prev && pair.second.m_next);
174176
pair.second.m_flags |= flags;
175177
}
176178
static void SetDirty(CoinsCachePair& pair, CoinsCachePair& sentinel) noexcept { AddFlags(DIRTY, pair, sentinel); }
@@ -182,6 +184,7 @@ struct CCoinsCacheEntry
182184
m_next->second.m_prev = m_prev;
183185
m_prev->second.m_next = m_next;
184186
m_flags = 0;
187+
m_prev = m_next = nullptr;
185188
}
186189
uint8_t GetFlags() const noexcept { return m_flags; }
187190
bool IsDirty() const noexcept { return m_flags & DIRTY; }

0 commit comments

Comments
 (0)