Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1e24cf6

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 the expedient of attaching them to the PostmasterContext which we were already taking care to delete (and where, indeed, this data used to live before commits e5e2fc8 and 7c45e3a). This saves a probably-usually-negligible amount of space per running backend. It also avoids leaving potentially-security-sensitive data lying around in memory in processes that don't need it. You'd have to be unusually paranoid to think that that amounts to a live security bug, so I've not gone so far as to forcibly zero the memory; but there surely isn't a good reason to keep this data around. Arguably this is a memory management bug in the aforementioned commits, but it doesn't seem important enough to back-patch.
1 parent d7c19d6 commit 1e24cf6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/backend/libpq/hba.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ tokenize_file(const char *filename, FILE *file,
386386
MemoryContext linecxt;
387387
MemoryContext oldcxt;
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

+13
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
#ifdef EXEC_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)