Bug fix: free the allocated memmory