Fixed memory leaks
Merge remote-tracking branch 'pasis/memleak'
Merge branch 'master' into xep-0223