Changes in source code to fix memory leak

In the most widely distributed version of the MATITK source code, there is a memory leak issue. It can be fixed by making the changes according to the the diff.txt file.