Fixes leaks in pause and resume.