Fix environment lookup in the case the environment in allocated but not entirely filled.