Fix use-after-free in GetAlterTriggerStateCommand() (#6413)

Fix use-after-free in GetAlterTriggerStateCommand() introduced in #6398.

(cherry picked from commit 517b72a9d5)
release-11.0-teja-backport-pr6507
Onur Tirtir 2022-10-10 16:38:21 +03:00
parent 9929d9240e
commit 99697fb1e5
1 changed files with 7 additions and 2 deletions

View File

@ -136,8 +136,6 @@ GetAlterTriggerStateCommand(Oid triggerId)
const char *quotedTrigName = quote_identifier(NameStr(triggerForm->tgname));
char enableDisableState = triggerForm->tgenabled;
heap_freetuple(triggerTuple);
const char *alterTriggerStateStr = NULL;
switch (enableDisableState)
{
@ -175,6 +173,13 @@ GetAlterTriggerStateCommand(Oid triggerId)
appendStringInfo(alterTriggerStateCommand, "ALTER TABLE %s %s TRIGGER %s;",
qualifiedRelName, alterTriggerStateStr, quotedTrigName);
/*
* Free triggerTuple at the end since quote_identifier() might not return
* a palloc'd string if given identifier doesn't need to be quoted, and in
* that case quotedTrigName would still be bound to triggerTuple.
*/
heap_freetuple(triggerTuple);
return alterTriggerStateCommand->data;
}