]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix an old corner-case bug in set_config_option: push_old_value has to be
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 26 May 2008 18:54:59 +0000 (18:54 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 26 May 2008 18:54:59 +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 05b7b1a68df94e496b667da1ac7c26d13944e624..3309fbf4e7ab606c9127d0e9f3dc3af96ba8a49b 100644 (file)
@@ -10,7 +10,7 @@
  * Written by Peter Eisentraut <peter_e@gmx.net>.
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.252.4.4 2006/05/21 20:11:25 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.252.4.5 2008/05/26 18:54:59 tgl Exp $
  *
  *--------------------------------------------------------------------
  */
@@ -3426,6 +3426,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))
                                        {
@@ -3438,9 +3442,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;
@@ -3510,6 +3511,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))
                                        {
@@ -3522,9 +3527,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;
@@ -3594,6 +3596,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))
                                        {
@@ -3606,9 +3612,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;
@@ -3691,6 +3694,10 @@ set_config_option(const char *name, const char *value,
                                        free(guc_string_workspace);
                                guc_string_workspace = newval;
 
+                               /* Save old value to support transaction abort */
+                               if (changeVal && !makeDefault)
+                                       push_old_value(&conf->gen);
+
                                if (conf->assign_hook)
                                {
                                        const char *hookresult;
@@ -3728,9 +3735,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);