Fix memory leak when reading in file