diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index f540bb6b23f..60336b31803 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -2158,9 +2158,17 @@ GetSnapshotData(Snapshot snapshot) snapshot->subxip = (TransactionId *) malloc(GetMaxSnapshotSubxidCount() * sizeof(TransactionId)); if (snapshot->subxip == NULL) + { + /* + * Clean up the Snapshot state before throwing the error, so that + * a retry does not see a partially-initialized snapshot. + */ + free(snapshot->xip); + snapshot->xip = NULL; ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); + } } /*