corrected memory leak in freeMatrix()