Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0b39231

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 allocatedin a short-term memory context, which is not the default behavior ofhash_create. Noted while looking through hash_create calls in connectionwith Robert Haas' recent complaint.This is a pre-existing bug, but it doesn't seem important enough toback-patch. The hash table is not so large that it would matter unless thishappened many times within a session, which seems quite unlikely.
1 parentd4d1885 commit0b39231

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
staticHTAB*
@@ -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)

[8]ページ先頭

©2009-2025 Movatter.jp