Copy errmsg for distributed deadlock error into heap (#5641)

multi_log_hook() 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.

I don't think we have faced with such a problem before but it seems worth
fixing as it is theoretically possible due to the reasoning above.
pull/5652/head^2
Onur Tirtir 2022-01-24 17:27:41 +03:00 committed by GitHub
parent 152e512aa9
commit ff3913ad99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -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");
}
}