Commit 0b392314 authored by Tom Lane's avatar Tom Lane

Avoid memory leak if pgstat_vacuum_stat is interrupted partway through.

The temporary hash tables made by pgstat_collect_oids should be allocated
in a short-term memory context, which is not the default behavior of
hash_create.  Noted while looking through hash_create calls in connection
with Robert Haas' recent complaint.

This is a pre-existing bug, but it doesn't seem important enough to
back-patch.  The hash table is not so large that it would matter unless this
happened many times within a session, which seems quite unlikely.
parent d4d1885e
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* Copyright (c) 2001-2009, PostgreSQL Global Development Group * Copyright (c) 2001-2009, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.193 2009/11/28 23:38:07 tgl Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.194 2009/12/27 19:40:07 tgl Exp $
* ---------- * ----------
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -1033,7 +1033,8 @@ pgstat_vacuum_stat(void) ...@@ -1033,7 +1033,8 @@ pgstat_vacuum_stat(void)
* *
* Collect the OIDs of all objects listed in the specified system catalog * Collect the OIDs of all objects listed in the specified system catalog
* into a temporary hash table. Caller should hash_destroy the result * into a temporary hash table. Caller should hash_destroy the result
* when done with it. * when done with it. (However, we make the table in CurrentMemoryContext
* so that it will be freed properly in event of an error.)
* ---------- * ----------
*/ */
static HTAB * static HTAB *
...@@ -1049,10 +1050,11 @@ pgstat_collect_oids(Oid catalogid) ...@@ -1049,10 +1050,11 @@ pgstat_collect_oids(Oid catalogid)
hash_ctl.keysize = sizeof(Oid); hash_ctl.keysize = sizeof(Oid);
hash_ctl.entrysize = sizeof(Oid); hash_ctl.entrysize = sizeof(Oid);
hash_ctl.hash = oid_hash; hash_ctl.hash = oid_hash;
hash_ctl.hcxt = CurrentMemoryContext;
htab = hash_create("Temporary table of OIDs", htab = hash_create("Temporary table of OIDs",
PGSTAT_TAB_HASH_SIZE, PGSTAT_TAB_HASH_SIZE,
&hash_ctl, &hash_ctl,
HASH_ELEM | HASH_FUNCTION); HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT);
rel = heap_open(catalogid, AccessShareLock); rel = heap_open(catalogid, AccessShareLock);
scan = heap_beginscan(rel, SnapshotNow, 0, NULL); scan = heap_beginscan(rel, SnapshotNow, 0, NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment