Fixes memory leaks.