int ssl_socket_close (CONNECTION * conn)
{
sslsockdata *data = conn->sockdata;
- SSL_shutdown (data->ssl);
+ if (data) {
+ SSL_shutdown (data->ssl);
- X509_free (data->cert);
- SSL_free (data->ssl);
- SSL_CTX_free (data->ctx);
+ X509_free (data->cert);
+ SSL_free (data->ssl);
+ SSL_CTX_free (data->ctx);
+ safe_free ((void **) &conn->sockdata);
+ }
return raw_socket_close (conn);
}
}
}
conn = (CONNECTION *) safe_calloc (1, sizeof (CONNECTION));
- conn->bufpos = 0;
- conn->available = 0;
+ conn->fd = -1;
memcpy (&conn->mx, mx, sizeof (conn->mx));
conn->mx.mbox = 0;
conn->preconnect = safe_strdup (ImapPreconnect);
while (conn)
{
/* what's up here? the last connection doesn't seem to be used */
- if (conn->fd)
+ if (conn->fd >= 0)
{
snprintf (buf, sizeof (buf), _("Closing connection to %s..."),
conn->mx.host);
if (connect (conn->fd, (struct sockaddr *) &sin, sizeof (sin)) < 0)
{
- close (conn->fd);
+ raw_socket_close (conn);
if (verbose)
{
mutt_perror ("connect");
int raw_socket_close (CONNECTION *conn)
{
- return close (conn->fd);
+ /* Close the descriptor and set it to -1 if successful.
+ * Returns the error code from close */
+ return close (conn->fd) || !(conn->fd = -1);
}
int raw_socket_read (CONNECTION *conn)