[Misc] Fix various address sanitizer issues
Description
- Fixes a number of memory leaks/incorrect buffer accesses found due to the address sanitizer.
Checklist
-
Documentation reflects the changes made. -
Merge Request title is clear, concise, and suitable as a changelog entry. See our contributing docs
References
Closes #1374 (closed)
Edited by Niels Alexander Buegel