Fix an old corner-case bug in set_config_option: push_old_value has to be
authorTom Lane <[email protected]>
Mon, 26 May 2008 18:54:50 +0000 (18:54 +0000)
committerTom Lane <[email protected]>
Mon, 26 May 2008 18:54:50 +0000 (18:54 +0000)
called before, not after, calling the assign_hook if any.  This is because
push_old_value might fail (due to palloc out-of-memory), and in that case
there would be no stack entry to tell transaction abort to undo the GUC
assignment.  Of course the actual assignment to the GUC variable hasn't
happened yet --- but the assign_hook might have altered subsidiary state.
Without a stack entry we won't call it again to make it undo such actions.
So this is necessary to make the world safe for assign_hooks with side
effects.  Per a discussion a couple weeks ago with Magnus.

Back-patch to 8.0.  7.x did not have the problem because it did not have
allocatable stacks of GUC values.

src/backend/utils/misc/guc.c

index 49d8f01812fc1f3e3f48d1c4cfd4433d337176f0..be82535084cbde5ab01d60a94eab2abfe667bf79 100644 (file)
@@ -3716,6 +3716,10 @@ set_config_option(const char *name, const char *value,
                                        source = conf->gen.reset_source;
                                }
 
+                               /* Save old value to support transaction abort */
+                               if (changeVal && !makeDefault)
+                                       push_old_value(&conf->gen);
+
                                if (conf->assign_hook)
                                        if (!(*conf->assign_hook) (newval, changeVal, source))
                                        {
@@ -3728,9 +3732,6 @@ set_config_option(const char *name, const char *value,
 
                                if (changeVal || makeDefault)
                                {
-                                       /* Save old value to support transaction abort */
-                                       if (!makeDefault)
-                                               push_old_value(&conf->gen);
                                        if (changeVal)
                                        {
                                                *conf->variable = newval;
@@ -3800,6 +3801,10 @@ set_config_option(const char *name, const char *value,
                                        source = conf->gen.reset_source;
                                }
 
+                               /* Save old value to support transaction abort */
+                               if (changeVal && !makeDefault)
+                                       push_old_value(&conf->gen);
+
                                if (conf->assign_hook)
                                        if (!(*conf->assign_hook) (newval, changeVal, source))
                                        {
@@ -3812,9 +3817,6 @@ set_config_option(const char *name, const char *value,
 
                                if (changeVal || makeDefault)
                                {
-                                       /* Save old value to support transaction abort */
-                                       if (!makeDefault)
-                                               push_old_value(&conf->gen);
                                        if (changeVal)
                                        {
                                                *conf->variable = newval;
@@ -3884,6 +3886,10 @@ set_config_option(const char *name, const char *value,
                                        source = conf->gen.reset_source;
                                }
 
+                               /* Save old value to support transaction abort */
+                               if (changeVal && !makeDefault)
+                                       push_old_value(&conf->gen);
+
                                if (conf->assign_hook)
                                        if (!(*conf->assign_hook) (newval, changeVal, source))
                                        {
@@ -3896,9 +3902,6 @@ set_config_option(const char *name, const char *value,
 
                                if (changeVal || makeDefault)
                                {
-                                       /* Save old value to support transaction abort */
-                                       if (!makeDefault)
-                                               push_old_value(&conf->gen);
                                        if (changeVal)
                                        {
                                                *conf->variable = newval;
@@ -3972,6 +3975,10 @@ set_config_option(const char *name, const char *value,
                                        break;
                                }
 
+                               /* Save old value to support transaction abort */
+                               if (changeVal && !makeDefault)
+                                       push_old_value(&conf->gen);
+
                                if (conf->assign_hook)
                                {
                                        const char *hookresult;
@@ -4011,9 +4018,6 @@ set_config_option(const char *name, const char *value,
 
                                if (changeVal || makeDefault)
                                {
-                                       /* Save old value to support transaction abort */
-                                       if (!makeDefault)
-                                               push_old_value(&conf->gen);
                                        if (changeVal)
                                        {
                                                set_string_field(conf, conf->variable, newval);