The recent patch to log changes in postgresql.conf settings dumped core
authorTom Lane
Thu, 12 Nov 2009 18:20:23 +0000 (18:20 +0000)
committerTom Lane
Thu, 12 Nov 2009 18:20:23 +0000 (18:20 +0000)
if the initial value of a string variable was NULL, which is entirely
possible.  Noted while experimenting with custom_variable_classes.

src/backend/utils/misc/guc-file.l

index 424caea13f5858d06a6249c5f9a6ee320fd106b7..208e54f10c1af24aa77c2a862be383ce703a3fe1 100644 (file)
@@ -4,7 +4,7 @@
  *
  * Copyright (c) 2000-2009, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.62 2009/10/03 18:04:57 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc-file.l,v 1.63 2009/11/12 18:20:23 tgl Exp $
  */
 
 %{
@@ -316,18 +316,33 @@ ProcessConfigFile(GucContext context)
 
        /* In SIGHUP cases in the postmaster, report changes */
        if (context == PGC_SIGHUP && !IsUnderPostmaster)
-           pre_value = pstrdup(GetConfigOption(item->name, false));
+       {
+           const char *preval = GetConfigOption(item->name, false);
+
+           /* string variables could be NULL; treat that as empty */
+           if (!preval)
+               preval = "";
+           /* must dup, else might have dangling pointer below */
+           pre_value = pstrdup(preval);
+       }
 
        if (set_config_option(item->name, item->value, context,
                                 PGC_S_FILE, GUC_ACTION_SET, true))
        {
            set_config_sourcefile(item->name, item->filename,
                                  item->sourceline);
-           if (pre_value &&
-               strcmp(pre_value, GetConfigOption(item->name, false)) != 0)
-               ereport(elevel,
-                       (errmsg("parameter \"%s\" changed to \"%s\"",
-                               item->name, item->value)));
+
+           if (pre_value)
+           {
+               const char *post_value = GetConfigOption(item->name, false);
+
+               if (!post_value)
+                   post_value = "";
+               if (strcmp(pre_value, post_value) != 0)
+                   ereport(elevel,
+                           (errmsg("parameter \"%s\" changed to \"%s\"",
+                                   item->name, item->value)));
+           }
        }
 
        if (pre_value)