From 129525f2b48685b639fae20d9efb44acda578507 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Tue, 12 Nov 2013 04:29:23 +0000 Subject: [PATCH] Fix memory leak and macro error (Bug #452) --- CHANGES | 3 ++- mxml-attr.c | 13 ++++--------- mxml-string.c | 12 ++---------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/CHANGES b/CHANGES index 853cf84..0ae272e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,4 @@ -CHANGES - 2013-07-03 +CHANGES - 2013-11-11 -------------------- CHANGES IN Mini-XML 2.8 @@ -6,6 +6,7 @@ CHANGES IN Mini-XML 2.8 - Now call docsetutil using xcrun on OS X. - mxmldoc did not escape special HTML characters inside @code foo@ comments. + - Fixed a memory leak in mxmlElementDeleteAttr (STR #452) CHANGES IN Mini-XML 2.7 diff --git a/mxml-attr.c b/mxml-attr.c index 49d1209..bb23cb1 100644 --- a/mxml-attr.c +++ b/mxml-attr.c @@ -3,7 +3,7 @@ * * Attribute support code for Mini-XML, a small XML-like file parsing library. * - * Copyright 2003-2010 by Michael R Sweet. + * Copyright 2003-2013 by Michael R Sweet. * * These coded instructions, statements, and computer programs are the * property of Michael R Sweet and are protected by Federal copyright @@ -12,14 +12,6 @@ * missing or damaged, see the license at: * * http://www.minixml.org/ - * - * Contents: - * - * mxmlElementDeleteAttr() - Delete an attribute. - * mxmlElementGetAttr() - Get an attribute. - * mxmlElementSetAttr() - Set an attribute. - * mxmlElementSetAttrf() - Set an attribute with a formatted value. - * mxml_set_attr() - Set or add an attribute name/value pair. */ /* @@ -90,6 +82,9 @@ mxmlElementDeleteAttr(mxml_node_t *node,/* I - Element */ memmove(attr, attr + 1, i * sizeof(mxml_attr_t)); node->value.element.num_attrs --; + + if (node->value.element.num_attrs == 0) + free(node->value.element.attrs); return; } } diff --git a/mxml-string.c b/mxml-string.c index d83e5ea..cbdb026 100644 --- a/mxml-string.c +++ b/mxml-string.c @@ -3,7 +3,7 @@ * * String functions for Mini-XML, a small XML-like file parsing library. * - * Copyright 2003-2010 by Michael R Sweet. + * Copyright 2003-2013 by Michael R Sweet. * * These coded instructions, statements, and computer programs are the * property of Michael R Sweet and are protected by Federal copyright @@ -12,14 +12,6 @@ * missing or damaged, see the license at: * * http://www.minixml.org/ - * - * Contents: - * - * _mxml_snprintf() - Format a string. - * _mxml_strdup() - Duplicate a string. - * _mxml_strdupf() - Format and duplicate a string. - * _mxml_vsnprintf() - Format a string into a fixed size buffer. - * _mxml_vstrdupf() - Format and duplicate a string. */ /* @@ -38,7 +30,7 @@ # ifdef __va_copy # define va_copy(dst,src) __va_copy(dst,src) # else -# define va_copy(dst,src) memcpy(&dst, &src, sizeof(va_list)) +# define va_copy(dst,src) memcpy(&dst, src, sizeof(va_list)) # endif /* __va_copy */ #endif /* va_copy */