summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rowley2023-02-13 10:38:21 +0000
committerDavid Rowley2023-02-13 10:38:21 +0000
commitec5a010ab25bf40012fde78b34724971e38e08a4 (patch)
tree617773338050b68f053354767ed3332d207e7dbf
parentbd944884e92af7082063428a1124a15041597c33 (diff)
Fix pfree issue in presorted DISTINCT aggregate code
The logic in this area was recently changed in 7da51590e, however, in that commit, I neglected to consider that the conditions in which we should pfree the old Datum needed to be updated after that change. This could result in trying to pfree a NULL value, as was demonstrated by Alexander Lakhin. Reported-by: Alexander Lakhin Discussion: https://postgr.es/m/[email protected]
-rw-r--r--src/backend/executor/execExprInterp.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/backend/executor/execExprInterp.c b/src/backend/executor/execExprInterp.c
index 827c65cc85..19351fe34b 100644
--- a/src/backend/executor/execExprInterp.c
+++ b/src/backend/executor/execExprInterp.c
@@ -4254,7 +4254,8 @@ ExecEvalPreOrderedDistinctSingle(AggState *aggstate, AggStatePerTrans pertrans)
pertrans->aggCollation,
pertrans->lastdatum, value))))
{
- if (pertrans->haslast && !pertrans->inputtypeByVal)
+ if (pertrans->haslast && !pertrans->inputtypeByVal &&
+ !pertrans->lastisnull)
pfree(DatumGetPointer(pertrans->lastdatum));
pertrans->haslast = true;