bitcoin/src/qt/test
Carl Dong 972c5166ee qt/test: Reset chainman in ~ChainstateManager instead
There are some mutable, global state variables that are currently reset
by UnloadBlockIndex such as pindexBestHeader which should be cleaned up
whenever the ChainstateManager is unloaded/reset/destructed/etc.

Not cleaning them up leads to bugs like a use-after-free that happens
like so:

1. At the end of a test, ChainstateManager is destructed, which also
   destructs BlockManager, which calls BlockManager::Unload to free all
   CBlockIndexes in its BlockMap
2. Since pindexBestHeader is not cleaned up, it now points to an invalid
   location
3. Another test starts to init, and calls LoadGenesisBlock, which calls
   AddToBlockIndex, which compares the genesis block with an invalid
   location
4. Cute puppies perish by the hundreds

Previously, for normal codepaths (e.g. bitcoind), we relied on the fact
that our program will be unloaded by the operating system which
effectively resets these variables. The one exception is in QT tests,
where these variables had to be manually reset.

Since now ChainstateManager is no longer a global, we can just put this
logic in its destructor to make sure that callers are always correct.

Over time, we should probably move these mutable global state variables
into ChainstateManager or CChainState so it's easier to reason about
their lifecycles.
2021-06-10 15:05:25 -04:00
..
addressbooktests.cpp refactor: move first run detection to client code 2021-05-19 08:50:16 +02:00
addressbooktests.h scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
apptests.cpp qt/test: Reset chainman in ~ChainstateManager instead 2021-06-10 15:05:25 -04:00
apptests.h scripted-diff: Bump copyright headers 2020-04-16 13:33:09 -04:00
Makefile build: add stub makefiles for easier subdir builds 2014-06-05 16:05:43 -04:00
rpcnestedtests.cpp test: Use loop to register RPCs 2021-05-03 11:50:05 +02:00
rpcnestedtests.h scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
test_main.cpp test: remove qt byteswap compattests 2021-03-29 11:12:26 +08:00
uritests.cpp Update copyright headers to 2018 2018-07-27 07:15:02 -04:00
uritests.h Bump copyright headers to 2015 2015-12-13 18:08:39 +01:00
util.cpp scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
util.h scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00
wallettests.cpp qt/test: Use existing chainman in ::TestGUI (can be scripted-diff) 2021-06-10 15:04:39 -04:00
wallettests.h scripted-diff: Bump copyright headers 2020-12-31 09:45:41 +01:00