src/irc_net.c
changeset 28 9c1050bc8709
parent 27 e6639132bead
child 37 4fe4a3c4496e
--- a/src/irc_net.c	Tue Mar 10 01:46:09 2009 +0200
+++ b/src/irc_net.c	Tue Mar 10 02:34:11 2009 +0200
@@ -30,7 +30,7 @@
 err_t irc_net_create (struct irc_net **net_ptr, const struct irc_net_info *info, struct error_info *err)
 {
     struct irc_net *net;
-    struct sock_stream *sock;
+    struct sock_stream *sock = NULL;
     
     // allocate
     if ((net = calloc(1, sizeof(*net))) == NULL)
@@ -54,13 +54,13 @@
 
     }
 
-    log_info("connected, registering");
-
     // create the irc connection state
     if (irc_conn_create(&net->conn, sock, &_conn_callbacks, net, err))
         goto error;
 
     // register
+    log_info("connected, registering");
+
     if ((ERROR_CODE(err) = irc_conn_register(net->conn, &info->register_info)))
         goto error;
     
@@ -70,7 +70,17 @@
     return SUCCESS;
 
 error:
-    // XXX: cleanup
+    // cleanup
+    if (net->conn)
+        // irc_conn takes care of the socket as well
+        irc_conn_destroy(net->conn);
+    
+    else if (sock)
+        // we need to clean up the socket ourself
+        sock_stream_release(sock);
+    
+    // release our state
+    free(net);
 
     return ERROR_CODE(err);
 }