[evolution-data-server] Bug #682398 - GError reuse during IMAP connect routine



commit efc20ad0eaf334a89159b58d67f153d66d04d7f9
Author: Milan Crha <mcrha redhat com>
Date:   Tue Sep 11 08:48:17 2012 +0200

    Bug #682398 - GError reuse during IMAP connect routine

 camel/camel-stream-buffer.c             |   18 ++++++++++++++----
 camel/camel-tcp-stream-ssl.c            |    1 +
 camel/providers/imap/camel-imap-store.c |   15 +++++++++------
 3 files changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/camel/camel-stream-buffer.c b/camel/camel-stream-buffer.c
index a76eb64..29a0499 100644
--- a/camel/camel-stream-buffer.c
+++ b/camel/camel-stream-buffer.c
@@ -499,6 +499,7 @@ camel_stream_buffer_gets (CamelStreamBuffer *sbf,
 {
 	register gchar *outptr, *inptr, *inend, c, *outend;
 	gint bytes_read;
+	GError *local_error = NULL;
 
 	outptr = buf;
 	inptr = (gchar *) sbf->priv->ptr;
@@ -520,11 +521,13 @@ camel_stream_buffer_gets (CamelStreamBuffer *sbf,
 
 		bytes_read = camel_stream_read (
 			sbf->priv->stream, (gchar *) sbf->priv->buf,
-			sbf->priv->size, cancellable, error);
+			sbf->priv->size, cancellable, &local_error);
 		if (bytes_read == -1) {
-			if (buf == outptr)
+			if (buf == outptr) {
+				if (local_error)
+					g_propagate_error (error, local_error);
 				return -1;
-			else
+			} else
 				bytes_read = 0;
 		}
 		sbf->priv->ptr = sbf->priv->buf;
@@ -536,6 +539,8 @@ camel_stream_buffer_gets (CamelStreamBuffer *sbf,
 	sbf->priv->ptr = (guchar *) inptr;
 	*outptr = 0;
 
+	g_clear_error (&local_error);
+
 	return (gint)(outptr - buf);
 }
 
@@ -559,16 +564,19 @@ camel_stream_buffer_read_line (CamelStreamBuffer *sbf,
 {
 	guchar *p;
 	gint nread;
+	GError *local_error = NULL;
 
 	p = sbf->priv->linebuf;
 
 	while (1) {
 		nread = camel_stream_buffer_gets (
 			sbf, (gchar *) p, sbf->priv->linesize -
-			(p - sbf->priv->linebuf), cancellable, error);
+			(p - sbf->priv->linebuf), cancellable, &local_error);
 		if (nread <=0) {
 			if (p > sbf->priv->linebuf)
 				break;
+			if (local_error)
+				g_propagate_error (error, local_error);
 			return NULL;
 		}
 
@@ -588,5 +596,7 @@ camel_stream_buffer_read_line (CamelStreamBuffer *sbf,
 		p--;
 	p[0] = 0;
 
+	g_clear_error (&local_error);
+
 	return g_strdup ((gchar *) sbf->priv->linebuf);
 }
diff --git a/camel/camel-tcp-stream-ssl.c b/camel/camel-tcp-stream-ssl.c
index ecea419..da0ccff 100644
--- a/camel/camel-tcp-stream-ssl.c
+++ b/camel/camel-tcp-stream-ssl.c
@@ -829,6 +829,7 @@ tcp_stream_ssl_connect (CamelTcpStream *stream,
 
 		if (!ssl_fd) {
 			d (g_print ("  could not enable SSL\n"));
+			return -1;
 		} else {
 			d (g_print ("  re-handshaking SSL\n"));
 
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index d43ac45..0bd0700 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -475,8 +475,8 @@ connect_to_server (CamelService *service,
 exception:
 
 	if (clean_quit && store->connected) {
-		/* try to disconnect cleanly */
-		response = camel_imap_command (store, NULL, cancellable, error, "LOGOUT");
+		/* try to disconnect cleanly; error is already set here */
+		response = camel_imap_command (store, NULL, cancellable, NULL, "LOGOUT");
 		if (response)
 			camel_imap_response_free_without_processing (store, response);
 	}
@@ -3302,6 +3302,7 @@ camel_imap_store_readline (CamelImapStore *store,
 	gchar linebuf[1024] = {0};
 	GByteArray *ba;
 	gssize nread;
+	GError *local_error = NULL;
 
 	g_return_val_if_fail (CAMEL_IS_IMAP_STORE (store), -1);
 	g_return_val_if_fail (dest, -1);
@@ -3319,21 +3320,23 @@ camel_imap_store_readline (CamelImapStore *store,
 	stream = CAMEL_STREAM_BUFFER (store->istream);
 
 	ba = g_byte_array_new ();
-	while ((nread = camel_stream_buffer_gets (stream, linebuf, sizeof (linebuf), cancellable, error)) > 0) {
+	while ((nread = camel_stream_buffer_gets (stream, linebuf, sizeof (linebuf), cancellable, &local_error)) > 0) {
 		g_byte_array_append (ba, (const guint8 *) linebuf, nread);
 		if (linebuf[nread - 1] == '\n')
 			break;
 	}
 
-	if (nread <= 0) {
-		if (nread == 0)
+	if (nread <= 0 || local_error) {
+		if (!local_error)
 			g_set_error (
 				error, CAMEL_SERVICE_ERROR,
 				CAMEL_SERVICE_ERROR_UNAVAILABLE,
 				_("Server unexpectedly disconnected"));
-		else
+		else {
+			g_propagate_error (error, local_error);
 			g_prefix_error (
 				error, _("Server unexpectedly disconnected: "));
+		}
 
 		/* do not pass cancellable, the connection is gone or
 		 * the cancellable cancelled, thus there will be no I/O */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]