Chevck first for NULL before writing anything to the alloceted structure