aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/utils/misc/guc.c47
1 files changed, 22 insertions, 25 deletions
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 0c9ed0908f6..07447d35e3f 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -6756,40 +6756,37 @@ replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p,
const char *name, const char *value)
{
ConfigVariable *item,
+ *next,
*prev = NULL;
- /* Search the list for an existing match (we assume there's only one) */
- for (item = *head_p; item != NULL; item = item->next)
+ /*
+ * Remove any existing match(es) for "name". Normally there'd be at most
+ * one, but if external tools have modified the config file, there could
+ * be more.
+ */
+ for (item = *head_p; item != NULL; item = next)
{
- if (strcmp(item->name, name) == 0)
+ next = item->next;
+ if (guc_name_compare(item->name, name) == 0)
{
- /* found a match, replace it */
- pfree(item->value);
- if (value != NULL)
- {
- /* update the parameter value */
- item->value = pstrdup(value);
- }
+ /* found a match, delete it */
+ if (prev)
+ prev->next = next;
else
- {
- /* delete the configuration parameter from list */
- if (*head_p == item)
- *head_p = item->next;
- else
- prev->next = item->next;
- if (*tail_p == item)
- *tail_p = prev;
+ *head_p = next;
+ if (next == NULL)
+ *tail_p = prev;
- pfree(item->name);
- pfree(item->filename);
- pfree(item);
- }
- return;
+ pfree(item->name);
+ pfree(item->value);
+ pfree(item->filename);
+ pfree(item);
}
- prev = item;
+ else
+ prev = item;
}
- /* Not there; no work if we're trying to delete it */
+ /* Done if we're trying to delete it */
if (value == NULL)
return;