fix condition for memory allocation