return nil when memory allocation fails
recovery error as much as possible