Memory leak fix:
+ cause of the memory leak was not closing file writer for the state dump