Fix leaks reported by Asan

Merged Waqar Ahmed requested to merge work/fix-leaks into 1.6

Merge request reports