check for NULL after malloc