Fix a use after free error
Summary: D18073 mistakenly introduced a use after free bug by avoiding a copy that was made on purpose and holding a reference to an iterator pointed item that is removed in the next line, causing the reference to be dangling.
Test Plan:
./contrib/teamcity/build-configurations.py build-asan
Reviewers: #bitcoin_abc, PiRK
Reviewed By: #bitcoin_abc, PiRK
Differential Revision: https://reviews.bitcoinabc.org/D18082