Fix potential memory leak in mxmlLoadXxx (Issue #278, Issue #279)

pull/288/head
Michael R Sweet 3 years ago
parent 02f3310322
commit bd4eb861a7
No known key found for this signature in database
GPG Key ID: 999559A027815955
  1. 1
      CHANGES.md
  2. 25
      mxml-file.c
  3. 4
      testmxml.c

@ -1,5 +1,6 @@
# Changes in Mini-XML 3.2.1
- Fixed potential memory leak in `mxmlLoad*` functions (Issue #278, Issue #279)
- Fixed `MXML_MINOR_VERSION` value in "mxml.h" (Issue #285)
- Fixed POSIX threading support for MingW (Issue #287)
- Fixed some minor memory leaks found by Coverity.

@ -1366,9 +1366,9 @@ mxml_load_data(
mxml_sax_cb_t sax_cb, /* I - SAX callback or MXML_NO_CALLBACK */
void *sax_data) /* I - SAX user data */
{
mxml_node_t *node, /* Current node */
*first, /* First node added */
*parent; /* Current parent node */
mxml_node_t *node = NULL, /* Current node */
*first = NULL, /* First node added */
*parent = NULL; /* Current parent node */
int line = 1, /* Current line number */
ch, /* Character from file */
whitespace; /* Non-zero if whitespace seen */
@ -1933,8 +1933,13 @@ mxml_load_data(
{
(*sax_cb)(node, MXML_SAX_ELEMENT_CLOSE, sax_data);
if (!mxmlRelease(node) && first == node)
first = NULL;
if (!mxmlRelease(node))
{
if (first == node)
first = NULL;
node = NULL;
}
}
/*
@ -1981,6 +1986,7 @@ mxml_load_data(
{
mxml_error("Expected > but got '%c' instead for element <%s/> on line %d.", ch, buffer, line);
mxmlDelete(node);
node = NULL;
goto error;
}
@ -2013,8 +2019,13 @@ mxml_load_data(
{
(*sax_cb)(node, MXML_SAX_ELEMENT_CLOSE, sax_data);
if (!mxmlRelease(node) && first == node)
first = NULL;
if (!mxmlRelease(node))
{
if (first == node)
first = NULL;
node = NULL;
}
}
}

@ -661,7 +661,7 @@ main(int argc, /* I - Number of command-line args */
memset(event_counts, 0, sizeof(event_counts));
if (argv[1][0] == '<')
mxmlSAXLoadString(NULL, argv[1], type_cb, sax_cb, NULL);
mxmlRelease(mxmlSAXLoadString(NULL, argv[1], type_cb, sax_cb, NULL));
else if ((fp = fopen(argv[1], "rb")) == NULL)
{
perror(argv[1]);
@ -673,7 +673,7 @@ main(int argc, /* I - Number of command-line args */
* Read the file...
*/
mxmlSAXLoadFile(NULL, fp, type_cb, sax_cb, NULL);
mxmlRelease(mxmlSAXLoadFile(NULL, fp, type_cb, sax_cb, NULL));
fclose(fp);
}

Loading…
Cancel
Save