Fix locking in SC_set_prepared
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 24 Feb 2014 13:44:50 +0000 (15:44 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 24 Feb 2014 13:44:50 +0000 (15:44 +0200)
Commit 2f4f8eabf6ce685c38d69da3e98132b77d38d188 added ENTER/LEAVE_CRIT_CS
calls in SC_set_prepared, as a belt-and-suspenders fix for the race condition
already fixed by commit 7065a7af196bb09f80beddce82fa728c8a6dfcba. But it
didn't take a NULL connection into account.

statement.c

index ee07973ab40fbeabf4f2eea00b5645fcefb04bb4..598f4022d437b293ec8d6050f85bd291812e996c 100644 (file)
@@ -683,24 +683,27 @@ SC_set_prepared(StatementClass *stmt, int prepared)
    {
        ConnectionClass *conn = SC_get_conn(stmt);
 
-       ENTER_CONN_CS(conn);
-       if (conn && CONN_CONNECTED == conn->status)
+       if (conn)
        {
-           if (CC_is_in_error_trans(conn))
-           {
-               CC_mark_a_object_to_discard(conn, 's',  stmt->plan_name);
-           }
-           else
+           ENTER_CONN_CS(conn);
+           if (CONN_CONNECTED == conn->status)
            {
-               QResultClass    *res;
-               char dealloc_stmt[128];
+               if (CC_is_in_error_trans(conn))
+               {
+                   CC_mark_a_object_to_discard(conn, 's',  stmt->plan_name);
+               }
+               else
+               {
+                   QResultClass    *res;
+                   char dealloc_stmt[128];
 
-               sprintf(dealloc_stmt, "DEALLOCATE \"%s\"", stmt->plan_name);
-               res = CC_send_query(conn, dealloc_stmt, NULL, IGNORE_ABORT_ON_CONN | ROLLBACK_ON_ERROR, NULL);
-               QR_Destructor(res);
-           } 
+                   sprintf(dealloc_stmt, "DEALLOCATE \"%s\"", stmt->plan_name);
+                   res = CC_send_query(conn, dealloc_stmt, NULL, IGNORE_ABORT_ON_CONN | ROLLBACK_ON_ERROR, NULL);
+                   QR_Destructor(res);
+               }
+           }
+           LEAVE_CONN_CS(conn);
        }
-       LEAVE_CONN_CS(conn);
    }
    if (NOT_YET_PREPARED == prepared)
        SC_set_planname(stmt, NULL);