Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
I fixed the memory leak. All that seemed to be needed was when starting the writing loop, just check if the file is empty, if it is not empty, close the file. As for the valgrind issue, thank you for bringing that information to my attention. I was not aware that it only reported the areas where the memory is.