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

Commit7d0ab65

Browse files
committed
Fix for aggregate memory leaks from Erik Riedel.
1 parent9ede867 commit7d0ab65

File tree

4 files changed

+76
-4
lines changed

4 files changed

+76
-4
lines changed

‎src/backend/executor/execMain.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.80 1999/03/19 18:56:36 momjian Exp $
29+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.81 1999/03/20 01:13:21 momjian Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -394,8 +394,26 @@ ExecutorEnd(QueryDesc *queryDesc, EState *estate)
394394

395395
EndPlan(queryDesc->plantree,estate);
396396

397+
/* XXX - clean up some more from ExecutorStart() - er1p */
398+
if (NULL==estate->es_snapshot) {
399+
/* nothing to free */
400+
}else {
401+
if (estate->es_snapshot->xcnt>0) {
402+
pfree(estate->es_snapshot->xip);
403+
}
404+
pfree(estate->es_snapshot);
405+
}
406+
407+
if (NULL==estate->es_param_exec_vals) {
408+
/* nothing to free */
409+
}else {
410+
pfree(estate->es_param_exec_vals);
411+
estate->es_param_exec_vals=NULL;
412+
}
413+
397414
/* restore saved refcounts. */
398415
BufferRefCountRestore(estate->es_refcount);
416+
399417
}
400418

401419
void
@@ -580,7 +598,7 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
580598
/*
581599
*initialize result relation stuff
582600
*/
583-
601+
584602
if (resultRelation!=0&&operation!=CMD_SELECT)
585603
{
586604
/*

‎src/backend/executor/execUtils.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.43 1999/02/13 23:15:20 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.44 1999/03/20 01:13:22 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -272,6 +272,7 @@ ExecAssignResultTypeFromTL(Plan *node, CommonState *commonstate)
272272
#endif
273273
i++;
274274
}
275+
275276
if (len>0)
276277
{
277278
ExecAssignResultType(commonstate,
@@ -368,6 +369,53 @@ ExecFreeProjectionInfo(CommonState *commonstate)
368369
commonstate->cs_ProjInfo=NULL;
369370
}
370371

372+
/* ----------------
373+
*ExecFreeExprContext
374+
* ----------------
375+
*/
376+
void
377+
ExecFreeExprContext(CommonState*commonstate)
378+
{
379+
ExprContext*econtext;
380+
381+
/* ----------------
382+
*get expression context. if NULL then this node has
383+
*none so we just return.
384+
* ----------------
385+
*/
386+
econtext=commonstate->cs_ExprContext;
387+
if (econtext==NULL)
388+
return;
389+
390+
/* ----------------
391+
*clean up memory used.
392+
* ----------------
393+
*/
394+
pfree(econtext);
395+
commonstate->cs_ExprContext=NULL;
396+
}
397+
398+
/* ----------------
399+
*ExecFreeTypeInfo
400+
* ----------------
401+
*/
402+
void
403+
ExecFreeTypeInfo(CommonState*commonstate)
404+
{
405+
TupleDesctupDesc;
406+
407+
tupDesc=commonstate->cs_ResultTupleSlot->ttc_tupleDescriptor;
408+
if (tupDesc==NULL)
409+
return;
410+
411+
/* ----------------
412+
*clean up memory used.
413+
* ----------------
414+
*/
415+
FreeTupleDesc(tupDesc);
416+
commonstate->cs_ResultTupleSlot->ttc_tupleDescriptor=NULL;
417+
}
418+
371419
/* ----------------------------------------------------------------
372420
*the following scan type support functions are for
373421
*those nodes which are stubborn and return tuples in

‎src/backend/executor/nodeAgg.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ ExecAgg(Agg *node)
110110
isNull2= FALSE;
111111
boolqual_result;
112112

113+
DatumoldVal= (Datum)NULL;/* XXX - so that we can save and free on each iteration - er1p */
113114

114115
/* ---------------------
115116
*get state info from node
@@ -372,8 +373,10 @@ ExecAgg(Agg *node)
372373
*/
373374
args[0]=value1[aggno];
374375
args[1]=newVal;
376+
oldVal=value1[aggno];/* XXX - save so we can free later - er1p */
375377
value1[aggno]=(Datum)fmgr_c(&aggfns->xfn1,
376378
(FmgrValues*)args,&isNull1);
379+
pfree(oldVal);/* XXX - new, let's free the old datum - er1p */
377380
Assert(!isNull1);
378381
}
379382
}

‎src/backend/executor/nodeResult.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* SeqScan (emp.all)
2828
*
2929
* IDENTIFICATION
30-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeResult.c,v 1.9 1999/02/13 23:15:26 momjian Exp $
30+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeResult.c,v 1.10 1999/03/20 01:13:22 momjian Exp $
3131
*
3232
*-------------------------------------------------------------------------
3333
*/
@@ -263,6 +263,8 @@ ExecEndResult(Result *node)
263263
* is freed at end-transaction time. -cim 6/2/91
264264
* ----------------
265265
*/
266+
ExecFreeExprContext(&resstate->cstate);/* XXX - new for us - er1p */
267+
ExecFreeTypeInfo(&resstate->cstate);/* XXX - new for us - er1p */
266268
ExecFreeProjectionInfo(&resstate->cstate);
267269

268270
/* ----------------
@@ -276,6 +278,7 @@ ExecEndResult(Result *node)
276278
* ----------------
277279
*/
278280
ExecClearTuple(resstate->cstate.cs_ResultTupleSlot);
281+
pfree(resstate);node->resstate=NULL;/* XXX - new for us - er1p */
279282
}
280283

281284
void

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp