Bugfix: double free when performing multiple reads
This is a fix for the bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=732702
The bug report outlines broken utf8 support, but I was able to reproduce by passing any file twice. The
bug comes from (1) not properly resetting instances when calling the various close_*() functions and
(2) calling the wrong close in the for loop of the main program.
Let me know if anything needs to change thanks.