[Commits] [SCM] claws branch, master, updated. 3.17.3-166-g9bb6504

ticho at claws-mail.org ticho at claws-mail.org
Fri Apr 26 00:33:46 CEST 2019


The branch, master has been updated
       via  9bb650480eaeb335c51b3127f78f0e71db309df6 (commit)
      from  82d9246acc83aa8e94e9d1585b38f7ee4cc8180d (commit)

Summary of changes:
 src/common/session.c                            |    2 +-
 src/common/socket.c                             |   10 ++++++----
 src/common/socket.h                             |    2 +-
 src/etpan/imap-thread.c                         |   18 ++++++++++++++----
 src/etpan/nntp-thread.c                         |   18 ++++++++++++++----
 src/plugins/notification/notification_lcdproc.c |    4 ++--
 6 files changed, 38 insertions(+), 16 deletions(-)


- Log -----------------------------------------------------------------
commit 9bb650480eaeb335c51b3127f78f0e71db309df6
Author: Andrej Kacian <ticho at claws-mail.org>
Date:   Fri Apr 26 00:28:58 2019 +0200

    Free a memory leak in libetpan-backed server connections
    
    We create a connection using our sock_connect() and let
    libetpan take over managing it. However, libetpan only
    needs the socket file descriptor, so we need to get rid
    of the rest of the returned SockInfo struct.

diff --git a/src/common/session.c b/src/common/session.c
index a6f19ea..2da8e16 100644
--- a/src/common/session.c
+++ b/src/common/session.c
@@ -388,7 +388,7 @@ static gint session_close(Session *session)
 	}
 
 	if (session->sock) {
-		sock_close(session->sock);
+		sock_close(session->sock, TRUE);
 		session->sock = NULL;
 		session->state = SESSION_DISCONNECTED;
 		debug_print("session (%p): closed\n", session);
diff --git a/src/common/socket.c b/src/common/socket.c
index fdc1589..c5814d7 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -1486,7 +1486,7 @@ Single-byte send() and recv().
 	return bp - buf;
 }
 
-gint sock_close(SockInfo *sock)
+gint sock_close(SockInfo *sock, gboolean close_fd)
 {
 	gint ret;
 
@@ -1503,11 +1503,13 @@ gint sock_close(SockInfo *sock)
 		g_source_remove(sock->g_source);
 	sock->g_source = 0;
 #endif
+	if (close_fd) {
 #ifdef G_OS_WIN32
-	shutdown(sock->sock, 1); /* complete transfer before close */
-	ret = closesocket(sock->sock);
+		shutdown(sock->sock, 1); /* complete transfer before close */
+		ret = closesocket(sock->sock);
 #else
-	ret = fd_close(sock->sock); 
+		ret = fd_close(sock->sock);
+	}
 #endif
 
 	g_free(sock->canonical_name);
diff --git a/src/common/socket.h b/src/common/socket.h
index 005f5a0..a1b17e5 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -108,7 +108,7 @@ gint sock_connect_async_cancel		(gint id);
 gint sock_read		(SockInfo *sock, gchar *buf, gint len);
 gint sock_write		(SockInfo *sock, const gchar *buf, gint len);
 gint sock_write_all	(SockInfo *sock, const gchar *buf, gint len);
-gint sock_close		(SockInfo *sock);
+gint sock_close		(SockInfo *sock, gboolean close_fd);
 
 /* Functions to directly work on FD.  They are needed for pipes */
 gint fd_connect_unix	(const gchar *path);
diff --git a/src/etpan/imap-thread.c b/src/etpan/imap-thread.c
index b68e303..eeccac7 100644
--- a/src/etpan/imap-thread.c
+++ b/src/etpan/imap-thread.c
@@ -78,17 +78,22 @@ static int do_mailimap_socket_connect(mailimap * imap, const char * server,
 		return MAILIMAP_ERROR_CONNECTION_REFUSED;
 
 	if (proxy_connect(sock, server, port, proxy_info) < 0) {
-		sock_close(sock);
+		sock_close(sock, TRUE);
 		return MAILIMAP_ERROR_CONNECTION_REFUSED;
 	}
 
 	stream = mailstream_socket_open_timeout(sock->sock,
 			imap->imap_timeout);
 	if (stream == NULL) {
-		sock_close(sock);
+		sock_close(sock, TRUE);
 		return MAILIMAP_ERROR_MEMORY;
 	}
 
+	/* Libetpan now has the socket fd, and we're not interested in
+	 * rest of the SockInfo struct. Let's free it, while not touching
+	 * the socket itself. */
+	sock_close(sock, FALSE);
+
 	return mailimap_connect(imap, stream);
 }
 
@@ -119,17 +124,22 @@ static int do_mailimap_ssl_connect_with_callback(mailimap * imap, const char * s
 	if (proxy_connect(sock, server, port, proxy_info) < 0) {
 		debug_print("Can not make proxy connection via %s:%d\n",
 				proxy_info->proxy_host, proxy_info->proxy_port);
-		sock_close(sock);
+		sock_close(sock, TRUE);
 		return MAILIMAP_ERROR_CONNECTION_REFUSED;
 	}
 
 	stream = mailstream_ssl_open_with_callback_timeout(sock->sock,
 			imap->imap_timeout, callback, data);
 	if (stream == NULL) {
-		sock_close(sock);
+		sock_close(sock, TRUE);
 		return MAILIMAP_ERROR_SSL;
 	}
 
+	/* Libetpan now has the socket fd, and we're not interested in
+	 * rest of the SockInfo struct. Let's free it, while not touching
+	 * the socket itself. */
+	sock_close(sock, FALSE);
+
 	return mailimap_connect(imap, stream);
 }
 
diff --git a/src/etpan/nntp-thread.c b/src/etpan/nntp-thread.c
index bf67cd0..5f5b31b 100644
--- a/src/etpan/nntp-thread.c
+++ b/src/etpan/nntp-thread.c
@@ -78,17 +78,22 @@ static int do_newsnntp_socket_connect(newsnntp * imap, const char * server,
 		return NEWSNNTP_ERROR_CONNECTION_REFUSED;
 
 	if (proxy_connect(sock, server, port, proxy_info) < 0) {
-		sock_close(sock);
+		sock_close(sock, TRUE);
 		return NEWSNNTP_ERROR_CONNECTION_REFUSED;
 	}
 
 	stream = mailstream_socket_open_timeout(sock->sock,
 			imap->nntp_timeout);
 	if (stream == NULL) {
-		sock_close(sock);
+		sock_close(sock, TRUE);
 		return NEWSNNTP_ERROR_MEMORY;
 	}
 
+	/* Libetpan now has the socket fd, and we're not interested in
+	 * rest of the SockInfo struct. Let's free it, while not touching
+	 * the socket itself. */
+	sock_close(sock, FALSE);
+
 	return newsnntp_connect(imap, stream);
 }
 
@@ -114,17 +119,22 @@ static int do_newsnntp_ssl_connect_with_callback(newsnntp * imap, const char * s
 		return NEWSNNTP_ERROR_CONNECTION_REFUSED;
 
 	if (proxy_connect(sock, server, port, proxy_info) < 0) {
-		sock_close(sock);
+		sock_close(sock, TRUE);
 		return NEWSNNTP_ERROR_CONNECTION_REFUSED;
 	}
 
 	stream = mailstream_ssl_open_with_callback_timeout(sock->sock,
 			imap->nntp_timeout, callback, data);
 	if (stream == NULL) {
-		sock_close(sock);
+		sock_close(sock, TRUE);
 		return NEWSNNTP_ERROR_SSL;
 	}
 
+	/* Libetpan now has the socket fd, and we're not interested in
+	 * rest of the SockInfo struct. Let's free it, while not touching
+	 * the socket itself. */
+	sock_close(sock, FALSE);
+
 	return newsnntp_connect(imap, stream);
 }
 
diff --git a/src/plugins/notification/notification_lcdproc.c b/src/plugins/notification/notification_lcdproc.c
index 874caa7..0f131d1 100644
--- a/src/plugins/notification/notification_lcdproc.c
+++ b/src/plugins/notification/notification_lcdproc.c
@@ -61,7 +61,7 @@ void notification_lcdproc_connect(void)
   if(sock == NULL || sock->state == CONN_FAILED) {
     debug_print("Could not connect to LCDd\n");
     if(sock && sock->state == CONN_FAILED) {
-      sock_close(sock);
+      sock_close(sock, TRUE);
       sock = NULL;
     }
     return;
@@ -116,7 +116,7 @@ void notification_lcdproc_disconnect(void)
 #ifndef G_OS_WIN32
     shutdown(sock->sock, SHUT_RDWR);
 #endif
-    sock_close(sock);
+    sock_close(sock, TRUE);
     sock = NULL;
   }
 }

-----------------------------------------------------------------------


hooks/post-receive
-- 
Claws Mail


More information about the Commits mailing list