Test if 'env' is NULL before doing memset() and strlen(),
the caller may pass NULL to freeenv().