Fix 'use after free' warnings
Description
The new compilers new throw warnings, if a pointer is used after being freed. In fact, this happened in two instances of the code, which are fixed in this MR.
News snippet
Fix 'use_after_free' warnings.
Checklist
-
I have checked that my code follows the Octopus coding standards -
I have added tests for all the new features added in this request.