fixed memory leaks
fix a bug where a calls would use the wrong memspace