Index: agent/seahorse-agent-io.c
===================================================================
RCS file: /cvs/gnome/seahorse/agent/seahorse-agent-io.c,v
retrieving revision 1.6.2.1
diff -U3 -r1.6.2.1 seahorse-agent-io.c
--- agent/seahorse-agent-io.c	19 May 2005 06:36:06 -0000	1.6.2.1
+++ agent/seahorse-agent-io.c	28 Aug 2005 19:34:11 -0000
@@ -147,21 +147,29 @@
     return 0;
 }
 
+/* Disconnect the connection */
+static void
+disconnect (SeahorseAgentConn *cn)
+{
+    /* The watch tag */
+    if (cn->stag) {
+        g_source_remove (cn->stag);
+        cn->stag = 0;
+
+        if (cn->iochannel)
+            g_io_channel_shutdown (cn->iochannel, TRUE, NULL);
+    }
+}        
+
 /* Free the given connection structure */
 static void
 free_conn (SeahorseAgentConn *cn)
 {
-    GError *err = NULL;
-
     if (cn->iochannel) {
-        if (cn->stag)
-            g_source_remove (cn->stag);
-
-        g_io_channel_shutdown (cn->iochannel, TRUE, &err);
-        g_clear_error (&err);
+        disconnect (cn);
 
-        cn->iochannel = 0;
-        cn->stag = 0;
+        g_io_channel_unref (cn->iochannel);
+        cn->iochannel = NULL;
     }
 
     g_connections = g_list_remove (g_connections, cn);
@@ -357,7 +365,7 @@
 
     else if (strcasecmp (string, ASS_BYE) == 0) {
         seahorse_agent_io_reply (cn, TRUE, "closing connection");
-        free_conn (cn);
+        disconnect (cn);
     }
 
     else if (strcasecmp (string, ASS_RESET) == 0) {
@@ -393,6 +401,7 @@
             g_critical ("couldn't read from socket: %s", err->message);
             g_clear_error (&err);
             free_conn (cn);
+            cn = NULL;
             ret = FALSE;
         }
 
@@ -405,7 +414,7 @@
             g_free (string);
     }
 
-    if (condition & G_IO_HUP) {
+    if (cn && condition & G_IO_HUP) {
         free_conn (cn);
         ret = FALSE;            /* removes watch */
     }
@@ -417,7 +426,8 @@
 static gboolean
 is_valid_conn (SeahorseAgentConn *cn)
 {
-    return cn && g_list_index (g_connections, cn) != -1;
+    return cn && cn->iochannel && 
+           g_list_index (g_connections, cn) != -1;
 }
 
 /* Write all passed data to socket */
@@ -440,7 +450,8 @@
         r = write (fd, data, len);
         if (r == -1) {
             if (errno != EAGAIN && errno != EINTR) {
-                g_critical ("couldn't write data to socket: %s", strerror (errno));
+                if (errno != EPIPE)
+                    g_critical ("couldn't write data to socket: %s", strerror (errno));
                 return -1;
             }
         }
@@ -471,7 +482,7 @@
         == -1 || (response && write_raw_data (fd, response, -1)) == -1
         || write_raw_data (fd, NL, KL (NL)) == -1) {
         /* error message already printed */
-        free_conn (cn);
+        disconnect (cn);
     }
 
     /* After sending back a response we're ready for more */
@@ -496,8 +507,7 @@
         return TRUE;            /* don't stop listening */
     }
 
-    cn = g_chunk_new (SeahorseAgentConn, g_memory);
-    memset (cn, 0, sizeof (*cn));
+    cn = g_chunk_new0 (SeahorseAgentConn, g_memory);
 
     g_connections = g_list_append (g_connections, cn);
 
@@ -537,7 +547,7 @@
     g_iochannel_tag = g_io_add_watch (g_iochannel, G_IO_IN, connect_handler, NULL);
 
     /* The main memory queue */
-    g_memory = g_mem_chunk_create (SeahorseAgentConn, 128, G_ALLOC_AND_FREE);
+    g_memory = g_mem_chunk_create (SeahorseAgentConn, 8, G_ALLOC_AND_FREE);
 
     return 0;
 }
