summaryrefslogtreecommitdiff
path: root/src/backend/libpq
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/libpq')
-rw-r--r--src/backend/libpq/be-secure.c5
-rw-r--r--src/backend/libpq/pqcomm.c23
2 files changed, 18 insertions, 10 deletions
diff --git a/src/backend/libpq/be-secure.c b/src/backend/libpq/be-secure.c
index 6e094965057..6ddcfd8476f 100644
--- a/src/backend/libpq/be-secure.c
+++ b/src/backend/libpq/be-secure.c
@@ -906,7 +906,6 @@ open_server_SSL(Port *port)
(errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("could not initialize SSL connection: %s",
SSLerrmessage())));
- close_SSL(port);
return -1;
}
if (!my_SSL_set_fd(port->ssl, port->sock))
@@ -915,7 +914,6 @@ open_server_SSL(Port *port)
(errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("could not set SSL socket: %s",
SSLerrmessage())));
- close_SSL(port);
return -1;
}
@@ -963,7 +961,6 @@ aloop:
err)));
break;
}
- close_SSL(port);
return -1;
}
@@ -992,7 +989,6 @@ aloop:
{
/* shouldn't happen */
pfree(peer_cn);
- close_SSL(port);
return -1;
}
@@ -1006,7 +1002,6 @@ aloop:
(errcode(ERRCODE_PROTOCOL_VIOLATION),
errmsg("SSL certificate's common name contains embedded null")));
pfree(peer_cn);
- close_SSL(port);
return -1;
}
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index 47b752aa154..9f35536a6eb 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -182,32 +182,45 @@ pq_comm_reset(void)
/* --------------------------------
* pq_close - shutdown libpq at backend exit
*
- * Note: in a standalone backend MyProcPort will be null,
- * don't crash during exit...
+ * This is the one pg_on_exit_callback in place during BackendInitialize().
+ * That function's unusual signal handling constrains that this callback be
+ * safe to run at any instant.
* --------------------------------
*/
static void
pq_close(int code, Datum arg)
{
+ /* Nothing to do in a standalone backend, where MyProcPort is NULL. */
if (MyProcPort != NULL)
{
#if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
#ifdef ENABLE_GSS
OM_uint32 min_s;
- /* Shutdown GSSAPI layer */
+ /*
+ * Shutdown GSSAPI layer. This section does nothing when interrupting
+ * BackendInitialize(), because pg_GSS_recvauth() makes first use of
+ * "ctx" and "cred".
+ */
if (MyProcPort->gss->ctx != GSS_C_NO_CONTEXT)
gss_delete_sec_context(&min_s, &MyProcPort->gss->ctx, NULL);
if (MyProcPort->gss->cred != GSS_C_NO_CREDENTIAL)
gss_release_cred(&min_s, &MyProcPort->gss->cred);
#endif /* ENABLE_GSS */
- /* GSS and SSPI share the port->gss struct */
+ /*
+ * GSS and SSPI share the port->gss struct. Since nowhere else does a
+ * postmaster child free this, doing so is safe when interrupting
+ * BackendInitialize().
+ */
free(MyProcPort->gss);
#endif /* ENABLE_GSS || ENABLE_SSPI */
- /* Cleanly shut down SSL layer */
+ /*
+ * Cleanly shut down SSL layer. Nowhere else does a postmaster child
+ * call this, so this is safe when interrupting BackendInitialize().
+ */
secure_close(MyProcPort);
/*