Added a free memory checking function