fix a possible endless loop in single memory allocation mode