Fixes some possible memory leaks.