summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2022-11-24 01:27:38 +0000
committerMichael Paquier2022-11-24 01:27:38 +0000
commitd46ad72f464beafa6d92d60d214412374559e280 (patch)
tree62934c9abb7c19aa803a8b42e857f48c96e7436a
parentd5566fbfeb6a1e05151a1cdc409465e2a3d3a6c6 (diff)
Create memory context for tokenization after opening top-level file in hba.c
The memory context was created before attempting to open the first HBA or ident file, which would cause it to leak. This had no consequences for the system views for HBA and ident files, but this would cause memory leaks in the postmaster on reload if the initial HBA and/or ident files are missing, which is a valid behavior while the backend is running. Oversight in efc9816. Author: Ted Yu Discussion: https://postgr.es/m/CALte62xH6ivgiKKzPRJgfekPZC6FKLB3xbnf3=tZmc_gKj78dw@mail.gmail.com
-rw-r--r--src/backend/libpq/hba.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c
index d6254d820f..1bd151c941 100644
--- a/src/backend/libpq/hba.c
+++ b/src/backend/libpq/hba.c
@@ -601,22 +601,6 @@ open_auth_file(const char *filename, int elevel, int depth,
return NULL;
}
- /*
- * When opening the top-level file, create the memory context used for the
- * tokenization. This will be closed with this file when coming back to
- * this level of cleanup.
- */
- if (depth == 0)
- {
- /*
- * A context may be present, but assume that it has been eliminated
- * already.
- */
- tokenize_context = AllocSetContextCreate(CurrentMemoryContext,
- "tokenize_context",
- ALLOCSET_START_SMALL_SIZES);
- }
-
file = AllocateFile(filename, "r");
if (file == NULL)
{
@@ -634,6 +618,22 @@ open_auth_file(const char *filename, int elevel, int depth,
return NULL;
}
+ /*
+ * When opening the top-level file, create the memory context used for the
+ * tokenization. This will be closed with this file when coming back to
+ * this level of cleanup.
+ */
+ if (depth == 0)
+ {
+ /*
+ * A context may be present, but assume that it has been eliminated
+ * already.
+ */
+ tokenize_context = AllocSetContextCreate(CurrentMemoryContext,
+ "tokenize_context",
+ ALLOCSET_START_SMALL_SIZES);
+ }
+
return file;
}