libfreerdp-core: fix leaks and potential use after free