Update the safeMalloc function