Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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


Attachment: node_agg_leak-1.patch
Description: text/x-patch (1.2 KB)


pgsql-patches by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group