take into account that memory allocation may fail