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

Commit1e24cf6

Browse files
committed
Don't leave pg_hba and pg_ident data lying around in running backends.
Free the contexts holding this data after we're done using it, by theexpedient of attaching them to the PostmasterContext which we werealready taking care to delete (and where, indeed, this data used to livebefore commitse5e2fc8 and7c45e3a). This saves aprobably-usually-negligible amount of space per running backend. It alsoavoids leaving potentially-security-sensitive data lying around in memoryin processes that don't need it. You'd have to be unusually paranoid tothink that that amounts to a live security bug, so I've not gone so far asto forcibly zero the memory; but there surely isn't a good reason to keepthis data around.Arguably this is a memory management bug in the aforementioned commits,but it doesn't seem important enough to back-patch.
1 parentd7c19d6 commit1e24cf6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

‎src/backend/libpq/hba.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ tokenize_file(const char *filename, FILE *file,
386386
MemoryContextlinecxt;
387387
MemoryContextoldcxt;
388388

389-
linecxt=AllocSetContextCreate(TopMemoryContext,
389+
linecxt=AllocSetContextCreate(CurrentMemoryContext,
390390
"tokenize file cxt",
391391
ALLOCSET_DEFAULT_MINSIZE,
392392
ALLOCSET_DEFAULT_INITSIZE,
@@ -1770,7 +1770,8 @@ load_hba(void)
17701770
FreeFile(file);
17711771

17721772
/* Now parse all the lines */
1773-
hbacxt=AllocSetContextCreate(TopMemoryContext,
1773+
Assert(PostmasterContext);
1774+
hbacxt=AllocSetContextCreate(PostmasterContext,
17741775
"hba parser context",
17751776
ALLOCSET_DEFAULT_MINSIZE,
17761777
ALLOCSET_DEFAULT_MINSIZE,
@@ -2147,7 +2148,8 @@ load_ident(void)
21472148
FreeFile(file);
21482149

21492150
/* Now parse all the lines */
2150-
ident_context=AllocSetContextCreate(TopMemoryContext,
2151+
Assert(PostmasterContext);
2152+
ident_context=AllocSetContextCreate(PostmasterContext,
21512153
"ident parser context",
21522154
ALLOCSET_DEFAULT_MINSIZE,
21532155
ALLOCSET_DEFAULT_MINSIZE,

‎src/backend/utils/init/postinit.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include"utils/acl.h"
5353
#include"utils/fmgroids.h"
5454
#include"utils/guc.h"
55+
#include"utils/memutils.h"
5556
#include"utils/pg_locale.h"
5657
#include"utils/portal.h"
5758
#include"utils/ps_status.h"
@@ -190,6 +191,18 @@ PerformAuthentication(Port *port)
190191
* FIXME: [fork/exec] Ugh. Is there a way around this overhead?
191192
*/
192193
#ifdefEXEC_BACKEND
194+
/*
195+
* load_hba() and load_ident() want to work within the PostmasterContext,
196+
* so create that if it doesn't exist (which it won't). We'll delete it
197+
* again later, in PostgresMain.
198+
*/
199+
if (PostmasterContext==NULL)
200+
PostmasterContext=AllocSetContextCreate(TopMemoryContext,
201+
"Postmaster",
202+
ALLOCSET_DEFAULT_MINSIZE,
203+
ALLOCSET_DEFAULT_INITSIZE,
204+
ALLOCSET_DEFAULT_MAXSIZE);
205+
193206
if (!load_hba())
194207
{
195208
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp