diff --git a/src/backend/executor/nodeWindowAgg.c b/src/backend/executor/nodeWindowAgg.c index 81ba024bba..083a3b2386 100644 --- a/src/backend/executor/nodeWindowAgg.c +++ b/src/backend/executor/nodeWindowAgg.c @@ -2234,6 +2234,21 @@ ExecWindowAgg(PlanState *pstate) if (winstate->numaggs > 0) eval_windowaggregates(winstate); } + else if (!winstate->top_window) + { + /* + * Otherwise, if we're not the top-window, we'd better fill the + * aggregate values in with something, else they might be pointing + * to freed memory. These don't need to be valid since WindowAggs + * above us cannot reference the result of another WindowAgg. + */ + numfuncs = winstate->numfuncs; + for (i = 0; i < numfuncs; i++) + { + econtext->ecxt_aggvalues[i] = (Datum) 0; + econtext->ecxt_aggnulls[i] = true; + } + } /* * If we have created auxiliary read pointers for the frame or group