Re: 8.3.0 backend segfaults - Mailing list pgsql-bugs

From Tom Lane
Subject Re: 8.3.0 backend segfaults
Date
Msg-id 4558.1205366426@sss.pgh.pa.us
Whole thread Raw
In response to Re: 8.3.0 backend segfaults  ("Alex Hunsaker" <badalex@gmail.com>)
Responses Re: 8.3.0 backend segfaults
List pgsql-bugs
This patch should fix it ...

            regards, tom lane

Index: postgres.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/tcop/postgres.c,v
retrieving revision 1.544
diff -c -r1.544 postgres.c
*** postgres.c    10 Mar 2008 12:55:13 -0000    1.544
--- postgres.c    12 Mar 2008 23:42:32 -0000
***************
*** 730,760 ****
  pg_plan_queries(List *querytrees, int cursorOptions, ParamListInfo boundParams,
                  bool needSnapshot)
  {
!     List       *stmt_list = NIL;
!     ListCell   *query_list;

!     foreach(query_list, querytrees)
      {
!         Query       *query = (Query *) lfirst(query_list);
!         Node       *stmt;

!         if (query->commandType == CMD_UTILITY)
          {
!             /* Utility commands have no plans. */
!             stmt = query->utilityStmt;
!         }
!         else
!         {
!             if (needSnapshot)
              {
!                 ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
!                 needSnapshot = false;
              }
!             stmt = (Node *) pg_plan_query(query, cursorOptions, boundParams);
          }

!         stmt_list = lappend(stmt_list, stmt);
      }

      return stmt_list;
  }
--- 730,778 ----
  pg_plan_queries(List *querytrees, int cursorOptions, ParamListInfo boundParams,
                  bool needSnapshot)
  {
!     List       * volatile stmt_list = NIL;
!     Snapshot    saveActiveSnapshot = ActiveSnapshot;

!     /* PG_TRY to ensure previous ActiveSnapshot is restored on error */
!     PG_TRY();
      {
!         Snapshot    mySnapshot = NULL;
!         ListCell   *query_list;

!         foreach(query_list, querytrees)
          {
!             Query       *query = (Query *) lfirst(query_list);
!             Node       *stmt;
!
!             if (query->commandType == CMD_UTILITY)
!             {
!                 /* Utility commands have no plans. */
!                 stmt = query->utilityStmt;
!             }
!             else
              {
!                 if (needSnapshot && mySnapshot == NULL)
!                 {
!                     mySnapshot = CopySnapshot(GetTransactionSnapshot());
!                     ActiveSnapshot = mySnapshot;
!                 }
!                 stmt = (Node *) pg_plan_query(query, cursorOptions,
!                                               boundParams);
              }
!
!             stmt_list = lappend(stmt_list, stmt);
          }

!         if (mySnapshot)
!             FreeSnapshot(mySnapshot);
!     }
!     PG_CATCH();
!     {
!         ActiveSnapshot = saveActiveSnapshot;
!         PG_RE_THROW();
      }
+     PG_END_TRY();
+     ActiveSnapshot = saveActiveSnapshot;

      return stmt_list;
  }

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: 8.3.0 backend segfaults
Next
From: "Alex Hunsaker"
Date:
Subject: Re: 8.3.0 backend segfaults