From 0ce0243f85f387aa451612c53e64061fdd48fbf9 Mon Sep 17 00:00:00 2001 From: angt Date: Tue, 2 Feb 2016 21:36:17 +0100 Subject: [PATCH] Memory cleanup --- mud.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mud.c b/mud.c index 7d37ec4..1b6aeb2 100644 --- a/mud.c +++ b/mud.c @@ -297,6 +297,26 @@ struct mud *mud_create (void) void mud_delete (struct mud *mud) { + if (!mud) + return; + + free(mud->tx.packet); + free(mud->rx.packet); + + while (mud->sock) { + struct sock *sock = mud->sock; + if (sock->fd != -1) + close(sock->fd); + mud->sock = sock->next; + free(sock); + } + + while (mud->path) { + struct path *path = mud->path; + mud->path = path->next; + free(path); + } + free(mud); }