summaryrefslogtreecommitdiff
path: root/win32/sendmail.c
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2015-03-03 15:37:08 +0100
committerAnatol Belski <ab@php.net>2015-03-03 17:19:15 +0100
commit74813e6f047f38ae648bdcf09ac1df838090ae35 (patch)
tree0bac8bd761cbfa046cda341eb8d0d9e129996fc8 /win32/sendmail.c
parentdcb944b35295833d7a90334ccdf08b56a3b707b2 (diff)
downloadphp-git-74813e6f047f38ae648bdcf09ac1df838090ae35.tar.gz
fix socket leaking and better connection err check
Diffstat (limited to 'win32/sendmail.c')
-rw-r--r--win32/sendmail.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/win32/sendmail.c b/win32/sendmail.c
index 9035c7d37e..194876ba4d 100644
--- a/win32/sendmail.c
+++ b/win32/sendmail.c
@@ -416,7 +416,11 @@ static int SendText(char *RPath, char *Subject, char *mailTo, char *mailCc, char
/* in the beginning of the dialog */
/* attempt reconnect if the first Post fail */
if ((res = Post(Buffer)) != SUCCESS) {
- MailConnect();
+ int err = MailConnect();
+ if (0 != err) {
+ return (FAILED_TO_SEND);
+ }
+
if ((res = Post(Buffer)) != SUCCESS) {
return (res);
}
@@ -785,12 +789,14 @@ static int MailConnect()
/* Get our own host name */
if (gethostname(LocalHost, HOST_NAME_LEN)) {
+ closesocket(sc);
return (FAILED_TO_GET_HOSTNAME);
}
ent = gethostbyname(LocalHost);
if (!ent) {
+ closesocket(sc);
return (FAILED_TO_GET_HOSTNAME);
}
@@ -803,6 +809,7 @@ static int MailConnect()
#endif
{
if (namelen + 2 >= HOST_NAME_LEN) {
+ closesocket(sc);
return (FAILED_TO_GET_HOSTNAME);
}
@@ -811,6 +818,7 @@ static int MailConnect()
strcpy(LocalHost + namelen + 1, "]");
} else {
if (namelen >= HOST_NAME_LEN) {
+ closesocket(sc);
return (FAILED_TO_GET_HOSTNAME);
}
@@ -836,6 +844,7 @@ static int MailConnect()
sock_in.sin_addr.S_un.S_addr = GetAddr(MailHost);
if (connect(sc, (LPSOCKADDR) & sock_in, sizeof(sock_in))) {
+ closesocket(sc);
return (FAILED_TO_CONNECT);
}