Memory leak in nodeAgg

From: Neil Conway <neilc(at)samurai(dot)com>
To: pgsql-patches(at)postgresql(dot)org
Subject: Memory leak in nodeAgg
Date: 2007-08-06 21:21:08
Message-ID: 1186435268.16321.37.camel@dell.linuxdev.us.dell.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
node_agg_leak-1.patch text/x-patch 1.2 KB

Responses

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2007-08-06 22:52:13 Re: Memory leak in nodeAgg
Previous Message Andrew Dunstan 2007-08-06 17:59:43 Re: COPYable logs