From 1272c3dfdb967f49ebb502f28ba3eb56e2360f54 Mon Sep 17 00:00:00 2001 From: Michael Sweet Date: Wed, 29 Mar 2017 18:18:22 -0400 Subject: [PATCH] Fix memory leak for mxmlDelete (Issue #183) --- mxml-node.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/mxml-node.c b/mxml-node.c index 92efeb7..35f957d 100644 --- a/mxml-node.c +++ b/mxml-node.c @@ -219,29 +219,23 @@ mxmlDelete(mxml_node_t *node) /* I - Node to delete */ if ((next = current->next) == NULL) { - mxml_node_t *temp = current->parent; - /* Pointer to parent node */ - - if (temp == node) - { - /* - * Got back to the top node... - */ + /* + * Next node is the parent, which we'll free as needed... + */ + if ((next = current->parent) == node) next = NULL; - } - else if ((next = temp->next) == NULL) - { - if ((next = temp->parent) == node) - next = NULL; - } } + /* + * Free child... + */ + mxml_free(current); } /* - * Then free the memory used by this node... + * Then free the memory used by the parent node... */ mxml_free(node);