Fix memory leakage after memory allocation failure.