Memory leak in nodeAgg - Mailing list pgsql-patches

From Neil Conway
Subject Memory leak in nodeAgg
Date
Msg-id 1186435268.16321.37.camel@dell.linuxdev.us.dell.com
Whole thread Raw
Responses Re: Memory leak in nodeAgg  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Memory leak in nodeAgg  (Neil Conway <neilc@samurai.com>)
List pgsql-patches
Attached is a patch that fixes a gradual memory leak in ExecReScanAgg(),
when the AGG_HASHED strategy is used:

    * the aggregation hash table is allocated in a newly-created
      sub-context of the agg's aggcontext

    * MemoryContextReset() resets the memory allocated in child
      contexts, but not the child contexts themselves

    * ExecReScanAgg() builds a brand-new hash table, which allocates
      a brand-new sub-context, thus leaking the header for the
      previous hashtable sub-context

The patch fixes this by using MemoryContextDeleteAndResetChildren(). (I
briefly looked at other call-sites of hash_create() to see if this
problem exists elsewhere, but I didn't see anything obvious.)

We run into the leak quite easily at Truviso; with a sufficiently
long-lived query in vanilla Postgres, you should be able to reproduce
the same problem.

Credit: Sailesh Krishnamurthy at Truviso for diagnosing the cause of the
leak.

-Neil


Attachment

pgsql-patches by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: COPYable logs
Next
From: Tom Lane
Date:
Subject: Re: Memory leak in nodeAgg