Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit642cd0a

Browse files
committed
Repair memory leakage introduced into the non-hashed aggregate case by
7.4 rewrite for hashed aggregate support. If the transition data typeis pass-by-reference, the transValue must be pfreed when starting a newgroup boundary, else we have a one-value-per-group leakage. Thanks toRae Steining for providing a reproducible test case.
1 parent58e3511 commit642cd0a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

‎src/backend/executor/nodeAgg.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
* Portions Copyright (c) 1994, Regents of the University of California
4646
*
4747
* IDENTIFICATION
48-
* $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.118 2004/02/03 17:34:02 tgl Exp $
48+
* $PostgreSQL: pgsql/src/backend/executor/nodeAgg.c,v 1.119 2004/03/13 00:54:10 tgl Exp $
4949
*
5050
*-------------------------------------------------------------------------
5151
*/
@@ -251,6 +251,18 @@ initialize_aggregates(AggState *aggstate,
251251
work_mem, false);
252252
}
253253

254+
/*
255+
* If we are reinitializing after a group boundary, we have to free
256+
* any prior transValue to avoid memory leakage. We must check not
257+
* only the isnull flag but whether the pointer is NULL; since
258+
* pergroupstate is initialized with palloc0, the initial condition
259+
* has isnull = 0 and null pointer.
260+
*/
261+
if (!peraggstate->transtypeByVal&&
262+
!pergroupstate->transValueIsNull&&
263+
DatumGetPointer(pergroupstate->transValue)!=NULL)
264+
pfree(DatumGetPointer(pergroupstate->transValue));
265+
254266
/*
255267
* (Re)set transValue to the initial value.
256268
*
@@ -1472,6 +1484,12 @@ ExecReScanAgg(AggState *node, ExprContext *exprCtxt)
14721484
build_hash_table(node);
14731485
node->table_filled= false;
14741486
}
1487+
else
1488+
{
1489+
/* Reset the per-group state (in particular, mark transvalues null) */
1490+
MemSet(node->pergroup,0,
1491+
sizeof(AggStatePerGroupData)*node->numaggs);
1492+
}
14751493

14761494
/*
14771495
* if chgParam of subnode is not null then plan will be re-scanned by

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp