diff --git a/src/backend/distributed/shared_library_init.c b/src/backend/distributed/shared_library_init.c index f74a3f43b..5e3ab85d2 100644 --- a/src/backend/distributed/shared_library_init.c +++ b/src/backend/distributed/shared_library_init.c @@ -446,8 +446,16 @@ multi_log_hook(ErrorData *edata) MyBackendGotCancelledDueToDeadlock(clearState)) { edata->sqlerrcode = ERRCODE_T_R_DEADLOCK_DETECTED; - edata->message = "canceling the transaction since it was " - "involved in a distributed deadlock"; + + /* + * This hook is called by EmitErrorReport() when emitting the ereport + * either to frontend or to the server logs. And some callers of + * EmitErrorReport() (e.g.: errfinish()) seems to assume that string + * fields of given ErrorData object needs to be freed. For this reason, + * we copy the message into heap here. + */ + edata->message = pstrdup("canceling the transaction since it was " + "involved in a distributed deadlock"); } }