fix some potential memory leaks