Skip to content

Commit 0b39231

Browse files
committed
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.
1 parent d4d1885 commit 0b39231

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/backend/postmaster/pgstat.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* Copyright (c) 2001-2009, PostgreSQL Global Development Group
1515
*
16-
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.193 2009/11/28 23:38:07 tgl Exp $
16+
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.194 2009/12/27 19:40:07 tgl Exp $
1717
* ----------
1818
*/
1919
#include "postgres.h"
@@ -1033,7 +1033,8 @@ pgstat_vacuum_stat(void)
10331033
*
10341034
* Collect the OIDs of all objects listed in the specified system catalog
10351035
* into a temporary hash table. Caller should hash_destroy the result
1036-
* when done with it.
1036+
* when done with it. (However, we make the table in CurrentMemoryContext
1037+
* so that it will be freed properly in event of an error.)
10371038
* ----------
10381039
*/
10391040
static HTAB *
@@ -1049,10 +1050,11 @@ pgstat_collect_oids(Oid catalogid)
10491050
hash_ctl.keysize = sizeof(Oid);
10501051
hash_ctl.entrysize = sizeof(Oid);
10511052
hash_ctl.hash = oid_hash;
1053+
hash_ctl.hcxt = CurrentMemoryContext;
10521054
htab = hash_create("Temporary table of OIDs",
10531055
PGSTAT_TAB_HASH_SIZE,
10541056
&hash_ctl,
1055-
HASH_ELEM | HASH_FUNCTION);
1057+
HASH_ELEM | HASH_FUNCTION | HASH_CONTEXT);
10561058

10571059
rel = heap_open(catalogid, AccessShareLock);
10581060
scan = heap_beginscan(rel, SnapshotNow, 0, NULL);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy