--- a/src/irc_net.c Thu Mar 12 23:05:54 2009 +0200
+++ b/src/irc_net.c Thu Mar 12 23:15:57 2009 +0200
@@ -174,21 +174,36 @@
return SUCCESS;
error:
- // cleanup
- if (net->conn)
- // irc_conn takes care of the socket as well
- irc_conn_destroy(net->conn);
-
- else if (sock)
+ if (sock && !net->conn)
// we need to clean up the socket ourself
sock_stream_release(sock);
- // release our state
- free(net);
+ // cleanup main
+ irc_net_destroy(net);
return ERROR_CODE(err);
}
+void irc_net_destroy (struct irc_net *net)
+{
+ struct irc_chan *next = TAILQ_FIRST(&net->channels), *chan;
+
+ // our conn
+ if (net->conn)
+ irc_conn_destroy(net->conn);
+
+ // our channels
+ while (next) {
+ chan = next;
+ next = TAILQ_NEXT(chan, node);
+
+ irc_chan_destroy(chan);
+ }
+
+ // ourselves
+ free(net);
+}
+
struct irc_chan* irc_net_add_chan (struct irc_net *net, const struct irc_chan_info *info)
{
struct irc_chan *chan;