mirror of
https://github.com/michaelrsweet/mxml.git
synced 2024-11-24 11:25:30 +00:00
Fix some minor Coverity memory leak issues.
This commit is contained in:
parent
0b1aa069c9
commit
1df294d735
@ -1,6 +1,7 @@
|
||||
# Changes in Mini-XML 3.2.1
|
||||
|
||||
- Fixed `MXML_MINOR_VERSION` value in "mxml.h" (Issue #285)
|
||||
- Fixed some minor memory leaks found by Coverity.
|
||||
|
||||
|
||||
# Changes in Mini-XML 3.2
|
||||
|
50
mxml-file.c
50
mxml-file.c
@ -3,7 +3,7 @@
|
||||
*
|
||||
* https://www.msweet.org/mxml
|
||||
*
|
||||
* Copyright © 2003-2020 by Michael R Sweet.
|
||||
* Copyright © 2003-2021 by Michael R Sweet.
|
||||
*
|
||||
* Licensed under Apache License v2.0. See the file "LICENSE" for more
|
||||
* information.
|
||||
@ -588,9 +588,7 @@ mxml_add_char(int ch, /* I - Character to add */
|
||||
|
||||
if ((newbuffer = realloc(*buffer, *bufsize)) == NULL)
|
||||
{
|
||||
free(*buffer);
|
||||
|
||||
mxml_error("Unable to expand string buffer to %d bytes!", *bufsize);
|
||||
mxml_error("Unable to expand string buffer to %d bytes.", *bufsize);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
@ -682,7 +680,7 @@ mxml_fd_getc(void *p, /* I - File descriptor buffer */
|
||||
|
||||
if (mxml_bad_char(ch))
|
||||
{
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard.",
|
||||
ch);
|
||||
return (EOF);
|
||||
}
|
||||
@ -746,7 +744,7 @@ mxml_fd_getc(void *p, /* I - File descriptor buffer */
|
||||
|
||||
if (ch < 0x80)
|
||||
{
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x!", ch);
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x.", ch);
|
||||
return (EOF);
|
||||
}
|
||||
}
|
||||
@ -780,7 +778,7 @@ mxml_fd_getc(void *p, /* I - File descriptor buffer */
|
||||
|
||||
if (ch < 0x800)
|
||||
{
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x!", ch);
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x.", ch);
|
||||
return (EOF);
|
||||
}
|
||||
|
||||
@ -832,7 +830,7 @@ mxml_fd_getc(void *p, /* I - File descriptor buffer */
|
||||
|
||||
if (ch < 0x10000)
|
||||
{
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x!", ch);
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x.", ch);
|
||||
return (EOF);
|
||||
}
|
||||
}
|
||||
@ -855,7 +853,7 @@ mxml_fd_getc(void *p, /* I - File descriptor buffer */
|
||||
|
||||
if (mxml_bad_char(ch))
|
||||
{
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard.",
|
||||
ch);
|
||||
return (EOF);
|
||||
}
|
||||
@ -903,7 +901,7 @@ mxml_fd_getc(void *p, /* I - File descriptor buffer */
|
||||
|
||||
if (mxml_bad_char(ch))
|
||||
{
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard.",
|
||||
ch);
|
||||
return (EOF);
|
||||
}
|
||||
@ -1096,7 +1094,7 @@ mxml_file_getc(void *p, /* I - Pointer to file */
|
||||
{
|
||||
if (mxml_bad_char(ch))
|
||||
{
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard.",
|
||||
ch);
|
||||
return (EOF);
|
||||
}
|
||||
@ -1148,7 +1146,7 @@ mxml_file_getc(void *p, /* I - Pointer to file */
|
||||
|
||||
if (ch < 0x80)
|
||||
{
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x!", ch);
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x.", ch);
|
||||
return (EOF);
|
||||
}
|
||||
}
|
||||
@ -1170,7 +1168,7 @@ mxml_file_getc(void *p, /* I - Pointer to file */
|
||||
|
||||
if (ch < 0x800)
|
||||
{
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x!", ch);
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x.", ch);
|
||||
return (EOF);
|
||||
}
|
||||
|
||||
@ -1204,7 +1202,7 @@ mxml_file_getc(void *p, /* I - Pointer to file */
|
||||
|
||||
if (ch < 0x10000)
|
||||
{
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x!", ch);
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x.", ch);
|
||||
return (EOF);
|
||||
}
|
||||
}
|
||||
@ -1221,7 +1219,7 @@ mxml_file_getc(void *p, /* I - Pointer to file */
|
||||
|
||||
if (mxml_bad_char(ch))
|
||||
{
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard.",
|
||||
ch);
|
||||
return (EOF);
|
||||
}
|
||||
@ -1250,7 +1248,7 @@ mxml_file_getc(void *p, /* I - Pointer to file */
|
||||
|
||||
if (mxml_bad_char(ch))
|
||||
{
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard.",
|
||||
ch);
|
||||
return (EOF);
|
||||
}
|
||||
@ -1398,7 +1396,7 @@ mxml_load_data(
|
||||
|
||||
if ((buffer = malloc(64)) == NULL)
|
||||
{
|
||||
mxml_error("Unable to allocate string buffer!");
|
||||
mxml_error("Unable to allocate string buffer.");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@ -1561,7 +1559,7 @@ mxml_load_data(
|
||||
break;
|
||||
else if (ch == '<')
|
||||
{
|
||||
mxml_error("Bare < in element!");
|
||||
mxml_error("Bare < in element.");
|
||||
goto error;
|
||||
}
|
||||
else if (ch == '&')
|
||||
@ -2119,7 +2117,7 @@ mxml_parse_element(
|
||||
|
||||
if ((name = malloc(64)) == NULL)
|
||||
{
|
||||
mxml_error("Unable to allocate memory for name!");
|
||||
mxml_error("Unable to allocate memory for name.");
|
||||
return (EOF);
|
||||
}
|
||||
|
||||
@ -2128,7 +2126,7 @@ mxml_parse_element(
|
||||
if ((value = malloc(64)) == NULL)
|
||||
{
|
||||
free(name);
|
||||
mxml_error("Unable to allocate memory for value!");
|
||||
mxml_error("Unable to allocate memory for value.");
|
||||
return (EOF);
|
||||
}
|
||||
|
||||
@ -2438,7 +2436,7 @@ mxml_string_getc(void *p, /* I - Pointer to file */
|
||||
|
||||
if (mxml_bad_char(ch))
|
||||
{
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard.",
|
||||
ch);
|
||||
return (EOF);
|
||||
}
|
||||
@ -2488,7 +2486,7 @@ mxml_string_getc(void *p, /* I - Pointer to file */
|
||||
|
||||
if (ch < 0x80)
|
||||
{
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x!", ch);
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x.", ch);
|
||||
return (EOF);
|
||||
}
|
||||
|
||||
@ -2514,7 +2512,7 @@ mxml_string_getc(void *p, /* I - Pointer to file */
|
||||
|
||||
if (ch < 0x800)
|
||||
{
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x!", ch);
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x.", ch);
|
||||
return (EOF);
|
||||
}
|
||||
|
||||
@ -2549,7 +2547,7 @@ mxml_string_getc(void *p, /* I - Pointer to file */
|
||||
|
||||
if (ch < 0x10000)
|
||||
{
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x!", ch);
|
||||
mxml_error("Invalid UTF-8 sequence for character 0x%04x.", ch);
|
||||
return (EOF);
|
||||
}
|
||||
|
||||
@ -2572,7 +2570,7 @@ mxml_string_getc(void *p, /* I - Pointer to file */
|
||||
|
||||
if (mxml_bad_char(ch))
|
||||
{
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard.",
|
||||
ch);
|
||||
return (EOF);
|
||||
}
|
||||
@ -2620,7 +2618,7 @@ mxml_string_getc(void *p, /* I - Pointer to file */
|
||||
|
||||
if (mxml_bad_char(ch))
|
||||
{
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard!",
|
||||
mxml_error("Bad control character 0x%02x not allowed by XML standard.",
|
||||
ch);
|
||||
return (EOF);
|
||||
}
|
||||
|
13
mxml-set.c
13
mxml-set.c
@ -3,7 +3,7 @@
|
||||
*
|
||||
* https://www.msweet.org/mxml
|
||||
*
|
||||
* Copyright © 2003-2019 by Michael R Sweet.
|
||||
* Copyright © 2003-2021 by Michael R Sweet.
|
||||
*
|
||||
* Licensed under Apache License v2.0. See the file "LICENSE" for more
|
||||
* information.
|
||||
@ -29,9 +29,6 @@ int /* O - 0 on success, -1 on failure */
|
||||
mxmlSetCDATA(mxml_node_t *node, /* I - Node to set */
|
||||
const char *data) /* I - New data string */
|
||||
{
|
||||
char *s; /* String pointer */
|
||||
|
||||
|
||||
/*
|
||||
* Range check input...
|
||||
*/
|
||||
@ -53,12 +50,8 @@ mxmlSetCDATA(mxml_node_t *node, /* I - Node to set */
|
||||
* Allocate the new value, free any old element value, and set the new value...
|
||||
*/
|
||||
|
||||
s = _mxml_strdupf("![CDATA[%s", data);
|
||||
|
||||
if (node->value.element.name)
|
||||
free(node->value.element.name);
|
||||
|
||||
node->value.element.name = s;
|
||||
free(node->value.element.name);
|
||||
node->value.element.name = _mxml_strdupf("![CDATA[%s", data);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
@ -228,7 +228,7 @@
|
||||
272CFFFD1E8C6664007EBCAC /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastUpgradeCheck = 1020;
|
||||
LastUpgradeCheck = 1310;
|
||||
ORGANIZATIONNAME = "Michael R Sweet";
|
||||
TargetAttributes = {
|
||||
272C00041E8C6664007EBCAC = {
|
||||
@ -344,6 +344,7 @@
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
@ -370,7 +371,7 @@
|
||||
GCC_WARN_UNUSED_LABEL = YES;
|
||||
GCC_WARN_UNUSED_PARAMETER = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.14;
|
||||
MTL_ENABLE_DEBUG_INFO = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
RUN_CLANG_STATIC_ANALYZER = YES;
|
||||
@ -407,6 +408,7 @@
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
@ -427,7 +429,7 @@
|
||||
GCC_WARN_UNUSED_LABEL = YES;
|
||||
GCC_WARN_UNUSED_PARAMETER = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.10;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.14;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
RUN_CLANG_STATIC_ANALYZER = YES;
|
||||
SDKROOT = macosx;
|
||||
@ -455,6 +457,7 @@
|
||||
272C003E1E8C6AEB007EBCAC /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
DEVELOPMENT_TEAM = RU58A2256H;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
@ -464,6 +467,7 @@
|
||||
272C003F1E8C6AEB007EBCAC /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_IDENTITY = "-";
|
||||
DEVELOPMENT_TEAM = RU58A2256H;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.12;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
|
Loading…
Reference in New Issue
Block a user