Cleanup leaking memory and filehandles