checking for NULL before free