!1066 修复打开慢sql后出现的内存泄漏

Merge pull request !1066 from 杨皓/1.1.0
This commit is contained in:
opengauss-bot 2021-07-01 02:44:58 +00:00 committed by Gitee
commit 601f3d2828
1 changed files with 4 additions and 1 deletions

View File

@ -528,7 +528,6 @@ static void CleanStatementTable()
static void FlushStatementToTable(StatementStatContext* suspendList, const knl_u_statement_context* statementCxt)
{
Assert (suspendList != NULL);
RangeVar* relrv = InitStatementRel();
HeapTuple tuple = NULL;
StatementStatContext *flushItem = suspendList;
@ -537,6 +536,8 @@ static void FlushStatementToTable(StatementStatContext* suspendList, const knl_u
PG_TRY();
{
StartTransactionCommand();
PushActiveSnapshot(GetTransactionSnapshot());
RangeVar* relrv = InitStatementRel();
Relation rel = heap_openrv(relrv, RowExclusiveLock);
while (flushItem != NULL) {
tuple = GetStatementTuple(rel, flushItem, statementCxt);
@ -546,6 +547,7 @@ static void FlushStatementToTable(StatementStatContext* suspendList, const knl_u
flushItem = (StatementStatContext *)flushItem->next;
}
heap_close(rel, RowExclusiveLock);
PopActiveSnapshot();
CommitTransactionCommand();
}
PG_CATCH();
@ -559,6 +561,7 @@ static void FlushStatementToTable(StatementStatContext* suspendList, const knl_u
ereport(WARNING, (errmodule(MOD_INSTR),
errmsg("[Statement] flush suspend list to statement_history failed, reason: '%s'", edata->message)));
FreeErrorData(edata);
PopActiveSnapshot();
AbortCurrentTransaction();
}
PG_END_TRY();