DISPATCH-1058 - Memory leak fixes and other fixes found by Coverity

(cherry picked from commit 9a48334eb32c261b527db1920a574dc5998f27b6)
3 files changed