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

Commita282697

Browse files
committed
Remove code in charge of freeing regexps generation by Lab.c
bea3d7e has redesigned the regexp engine so as all the allocations gothrough palloc() with a dedicated memory context. hba.c had to copewith the past memory management logic by going through all the HBA andident lines generated, then directly free all the regexps found inAuthTokens to ensure that no leaks would happen. Such leaks couldhappen for example in the postmaster after a SIGHUP, in the event ofan HBA and/or ident reload failure where all the new content parsed mustbe discarded, including all the regexps that may have been compiled.Now that regexps are palloc()'d in their own memory context,MemoryContextDelete() is enough to ensure that all the compiled regexpsare properly gone. Simplifying this logic in hba.c has the effect toonly remove code. Most of it is new in v16, except the part for regexpscompiled in ident entries for the system username, so doing this cleanupnow rather than when v17 opens for business will reduce future diffswith the upcoming REL_16_STABLE.Some comments were incorrect sincebea3d7e, now fixed to reflect thereality.Reviewed-by: Bertrand Drouvot, Álvaro HerreraDiscussion:https://postgr.es/m/ZDdJ289Ky2qEj4h+@paquier.xyz
1 parent0981846 commita282697

File tree

1 file changed

+5
-67
lines changed

1 file changed

+5
-67
lines changed

‎src/backend/libpq/hba.c

Lines changed: 5 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ static MemoryContext parsed_hba_context = NULL;
9595
/*
9696
* pre-parsed content of ident mapping file: list of IdentLine structs.
9797
* parsed_ident_context is the memory context where it lives.
98-
*
99-
* NOTE: the IdentLine structs can contain AuthTokens with pre-compiled
100-
* regular expressions that live outside the memory context. Before
101-
* destroying or resetting the memory context, they need to be explicitly
102-
* free'd.
10398
*/
10499
staticList*parsed_ident_lines=NIL;
105100
staticMemoryContextparsed_ident_context=NULL;
@@ -316,30 +311,6 @@ free_auth_token(AuthToken *token)
316311
pg_regfree(token->regex);
317312
}
318313

319-
/*
320-
* Free a HbaLine. Its list of AuthTokens for databases and roles may include
321-
* regular expressions that need to be cleaned up explicitly.
322-
*/
323-
staticvoid
324-
free_hba_line(HbaLine*line)
325-
{
326-
ListCell*cell;
327-
328-
foreach(cell,line->roles)
329-
{
330-
AuthToken*tok=lfirst(cell);
331-
332-
free_auth_token(tok);
333-
}
334-
335-
foreach(cell,line->databases)
336-
{
337-
AuthToken*tok=lfirst(cell);
338-
339-
free_auth_token(tok);
340-
}
341-
}
342-
343314
/*
344315
* Copy a AuthToken struct into freshly palloc'd memory.
345316
*/
@@ -2722,30 +2693,14 @@ load_hba(void)
27222693
if (!ok)
27232694
{
27242695
/*
2725-
* File contained one or more errors, so bail out, first being careful
2726-
* to clean up whatever we allocated. Most stuff will go away via
2727-
* MemoryContextDelete, but we have to clean up regexes explicitly.
2696+
* File contained one or more errors, so bail out. MemoryContextDelete
2697+
* is enough to clean up everything, including regexes.
27282698
*/
2729-
foreach(line,new_parsed_lines)
2730-
{
2731-
HbaLine*newline= (HbaLine*)lfirst(line);
2732-
2733-
free_hba_line(newline);
2734-
}
27352699
MemoryContextDelete(hbacxt);
27362700
return false;
27372701
}
27382702

27392703
/* Loaded new file successfully, replace the one we use */
2740-
if (parsed_hba_lines!=NIL)
2741-
{
2742-
foreach(line,parsed_hba_lines)
2743-
{
2744-
HbaLine*newline= (HbaLine*)lfirst(line);
2745-
2746-
free_hba_line(newline);
2747-
}
2748-
}
27492704
if (parsed_hba_context!=NULL)
27502705
MemoryContextDelete(parsed_hba_context);
27512706
parsed_hba_context=hbacxt;
@@ -3044,8 +2999,7 @@ load_ident(void)
30442999
{
30453000
FILE*file;
30463001
List*ident_lines=NIL;
3047-
ListCell*line_cell,
3048-
*parsed_line_cell;
3002+
ListCell*line_cell;
30493003
List*new_parsed_lines=NIL;
30503004
boolok= true;
30513005
MemoryContextoldcxt;
@@ -3102,30 +3056,14 @@ load_ident(void)
31023056
if (!ok)
31033057
{
31043058
/*
3105-
* File contained one or more errors, so bail out, first being careful
3106-
* to clean up whatever we allocated. Most stuff will go away via
3107-
* MemoryContextDelete, but we have to clean up regexes explicitly.
3059+
* File contained one or more errors, so bail out. MemoryContextDelete
3060+
* is enough to clean up everything, including regexes.
31083061
*/
3109-
foreach(parsed_line_cell,new_parsed_lines)
3110-
{
3111-
newline= (IdentLine*)lfirst(parsed_line_cell);
3112-
free_auth_token(newline->system_user);
3113-
free_auth_token(newline->pg_user);
3114-
}
31153062
MemoryContextDelete(ident_context);
31163063
return false;
31173064
}
31183065

31193066
/* Loaded new file successfully, replace the one we use */
3120-
if (parsed_ident_lines!=NIL)
3121-
{
3122-
foreach(parsed_line_cell,parsed_ident_lines)
3123-
{
3124-
newline= (IdentLine*)lfirst(parsed_line_cell);
3125-
free_auth_token(newline->system_user);
3126-
free_auth_token(newline->pg_user);
3127-
}
3128-
}
31293067
if (parsed_ident_context!=NULL)
31303068
MemoryContextDelete(parsed_ident_context);
31313069

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp