fixed segfault bug due to incorrectly handling persistent tempfiles