Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ec5a010

Browse files
committed
Fix pfree issue in presorted DISTINCT aggregate code
The logic in this area was recently changed in 7da5159, 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]
1 parent bd94488 commit ec5a010

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/backend/executor/execExprInterp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4254,7 +4254,8 @@ ExecEvalPreOrderedDistinctSingle(AggState *aggstate, AggStatePerTrans pertrans)
42544254
pertrans->aggCollation,
42554255
pertrans->lastdatum, value))))
42564256
{
4257-
if (pertrans->haslast && !pertrans->inputtypeByVal)
4257+
if (pertrans->haslast && !pertrans->inputtypeByVal &&
4258+
!pertrans->lastisnull)
42584259
pfree(DatumGetPointer(pertrans->lastdatum));
42594260

42604261
pertrans->haslast = true;

0 commit comments

Comments
 (0)