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

Fix use-after-free in GetAlterTriggerStateCommand() introduced in #6398.
pull/6418/head
Onur Tirtir 2022-10-10 16:38:21 +03:00 committed by GitHub
parent 1776bdf654
commit 517b72a9d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 2 deletions

View File

@ -139,8 +139,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)
{
@ -178,6 +176,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;
}