memory leaks when writing to a file

When I write to a file from a c++ class , I find that memory leaks occur.
This is especially true if I make a relatively large number of writes.
When I execute:
cat /proc/meminfo
run the program in question.
cat /proc/meminfo
The second /cat/procmeminfo shows that the amount of memory available is
considerably less.
I have run some tests and I have determined that writing to the file causes
the memory leak.
I am attaching a .tgz file which will illustrate this problem.
Please let me know why the memory leak occurs.
Thanks in advance.
Mark Schapira
(See attached file: writetest.tgz)