r1.39: initialize err to revent segfault r1.40: only free() the backend struct if we allocated it (don't free cached connections) Bump PKGREVISION.
80 lines
2.3 KiB
Text
80 lines
2.3 KiB
Text
$NetBSD: patch-ae,v 1.6 2006/10/09 12:46:01 obache Exp $
|
|
|
|
--- imap/backend.c.orig 2006-02-08 05:57:27.000000000 +0900
|
|
+++ imap/backend.c
|
|
@@ -264,25 +264,28 @@ static void timed_out(int sig)
|
|
}
|
|
}
|
|
|
|
-struct backend *backend_connect(struct backend *ret, const char *server,
|
|
+struct backend *backend_connect(struct backend *ret_backend, const char *server,
|
|
struct protocol_t *prot, const char *userid,
|
|
const char **auth_status)
|
|
{
|
|
/* need to (re)establish connection to server or create one */
|
|
int sock = -1;
|
|
int r;
|
|
- int err = 0;
|
|
+ int err = -1;
|
|
struct addrinfo hints, *res0 = NULL, *res1 = NULL, *res;
|
|
struct sockaddr_un sunsock;
|
|
char buf[2048], *mechlist = NULL;
|
|
struct sigaction action;
|
|
+ struct backend *ret;
|
|
|
|
- if (!ret) {
|
|
+ if (!ret_backend) {
|
|
ret = xmalloc(sizeof(struct backend));
|
|
memset(ret, 0, sizeof(struct backend));
|
|
strlcpy(ret->hostname, server, sizeof(ret->hostname));
|
|
ret->timeout = NULL;
|
|
}
|
|
+ else
|
|
+ ret = ret_backend;
|
|
|
|
if (server[0] == '/') { /* unix socket */
|
|
res0 = &hints;
|
|
@@ -312,7 +315,7 @@ struct backend *backend_connect(struct b
|
|
if (err) {
|
|
syslog(LOG_ERR, "getaddrinfo(%s) failed: %s",
|
|
server, gai_strerror(err));
|
|
- free(ret);
|
|
+ if (!ret_backend) free(ret);
|
|
return NULL;
|
|
}
|
|
/* Get addrinfo struct for local interface. */
|
|
@@ -363,7 +366,7 @@ struct backend *backend_connect(struct b
|
|
if (res0 != &hints)
|
|
freeaddrinfo(res0);
|
|
syslog(LOG_ERR, "connect(%s) failed: %m", server);
|
|
- free(ret);
|
|
+ if (!ret_backend) free(ret);
|
|
return NULL;
|
|
}
|
|
memcpy(&ret->addr, res->ai_addr, res->ai_addrlen);
|
|
@@ -381,7 +384,7 @@ struct backend *backend_connect(struct b
|
|
syslog(LOG_ERR,
|
|
"backend_connect(): couldn't read initial greeting: %s",
|
|
ret->in->error ? ret->in->error : "(null)");
|
|
- free(ret);
|
|
+ if (!ret_backend) free(ret);
|
|
close(sock);
|
|
return NULL;
|
|
}
|
|
@@ -396,13 +399,15 @@ struct backend *backend_connect(struct b
|
|
if ((r = backend_authenticate(ret, prot, &mechlist, userid, auth_status))) {
|
|
syslog(LOG_ERR, "couldn't authenticate to backend server: %s",
|
|
sasl_errstring(r, NULL, NULL));
|
|
- free(ret);
|
|
+ if (!ret_backend) free(ret);
|
|
close(sock);
|
|
ret = NULL;
|
|
}
|
|
}
|
|
|
|
if (mechlist) free(mechlist);
|
|
+
|
|
+ if (!ret_backend) ret_backend = ret;
|
|
|
|
return ret;
|
|
}
|