FS-11785 [core, mod_commands] update XML API to fix scan-build false positive memory leaks

This commit is contained in:
Chris Rienzo 2019-04-15 22:08:20 +00:00 committed by Andrey Volk
parent 3f46ce1da2
commit c776680c56
3 changed files with 42 additions and 10 deletions

View File

@ -266,8 +266,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_add_child(_In_ switch_xml_t xml, _In_z_
///\param xml the xml node
///\param name the name of the child
///\param off the offset
#define switch_xml_add_child_d(xml, name, off) \
switch_xml_set_flag(switch_xml_add_child(xml, strdup(name), off), SWITCH_XML_NAMEM)
SWITCH_DECLARE(switch_xml_t) switch_xml_add_child_d(_In_ switch_xml_t xml, _In_z_ const char *name, _In_ switch_size_t off);
///\brief sets the character content for the given tag and returns the tag
///\param xml the xml node
@ -280,8 +279,7 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt(switch_xml_t xml, const char *tx
///\param xml the xml node
///\param txt the text
///\return an xml node or NULL
#define switch_xml_set_txt_d(xml, txt) \
switch_xml_set_flag(switch_xml_set_txt(xml, strdup(txt)), SWITCH_XML_TXTM)
SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt_d(switch_xml_t xml, const char *txt);
///\brief Sets the given tag attribute or adds a new attribute if not found. A value
///\ of NULL will remove the specified attribute.
@ -296,11 +294,14 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr(switch_xml_t xml, const char *n
///\param name the attribute name
///\param value the attribute value
///\return an xml node or NULL
#define switch_xml_set_attr_d(xml, name, value) \
switch_xml_set_attr(switch_xml_set_flag(xml, SWITCH_XML_DUP), strdup(name), strdup(switch_str_nil(value)))
SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr_d(switch_xml_t xml, const char *name, const char *value);
#define switch_xml_set_attr_d_buf(xml, name, value) \
switch_xml_set_attr(switch_xml_set_flag(xml, SWITCH_XML_DUP), strdup(name), strdup(value))
///\brief Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL
///\param xml the xml node
///\param name the attribute name
///\param value the attribute value
///\return an xml node or NULL
SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr_d_buf(switch_xml_t xml, const char *name, const char *value);
///\brief sets a flag for the given tag and returns the tag
///\param xml the xml node

View File

@ -5473,7 +5473,7 @@ static int show_as_xml_callback(void *pArg, int argc, char **argv, char **column
switch_snprintf(id, sizeof(id), "%d", holder->rows);
switch_xml_set_attr(switch_xml_set_flag(row, SWITCH_XML_DUP), strdup("row_id"), strdup(id));
switch_xml_set_attr_d_buf(row, "row_id", id);
for (x = 0; x < argc; x++) {
char *name = columnNames[x];
@ -5864,7 +5864,7 @@ SWITCH_STANDARD_API(show_function)
char *xmlstr;
switch_snprintf(count, sizeof(count), "%d", holder.count);
switch_xml_set_attr(switch_xml_set_flag(holder.xml, SWITCH_XML_DUP), strdup("row_count"), strdup(count));
switch_xml_set_attr(holder.xml, "row_count", count);
xmlstr = switch_xml_toxml(holder.xml, SWITCH_FALSE);
switch_xml_free(holder.xml);

View File

@ -2942,6 +2942,14 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_add_child(switch_xml_t xml, const char *
return switch_xml_insert(child, xml, off);
}
/* Adds a child tag. off is the offset of the child tag relative to the start
of the parent tag's character content. Returns the child tag */
SWITCH_DECLARE(switch_xml_t) switch_xml_add_child_d(switch_xml_t xml, const char *name, switch_size_t off)
{
if (!xml) return NULL;
return switch_xml_set_flag(switch_xml_add_child(xml, strdup(name), off), SWITCH_XML_NAMEM);
}
/* sets the character content for the given tag and returns the tag */
SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt(switch_xml_t xml, const char *txt)
{
@ -2954,6 +2962,13 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt(switch_xml_t xml, const char *tx
return xml;
}
/* sets the character content for the given tag and returns the tag */
SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt_d(switch_xml_t xml, const char *txt)
{
if (!xml) return NULL;
return switch_xml_set_flag(switch_xml_set_txt(xml, strdup(txt)), SWITCH_XML_TXTM);
}
/* Sets the given tag attribute or adds a new attribute if not found. A value
of NULL will remove the specified attribute. Returns the tag given */
SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr(switch_xml_t xml, const char *name, const char *value)
@ -3005,6 +3020,22 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr(switch_xml_t xml, const char *n
return xml;
}
/* Sets the given tag attribute or adds a new attribute if not found. A value
of NULL will remove the specified attribute. Returns the tag given */
SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr_d(switch_xml_t xml, const char *name, const char *value)
{
if (!xml) return NULL;
return switch_xml_set_attr(switch_xml_set_flag(xml, SWITCH_XML_DUP), strdup(name), strdup(switch_str_nil(value)));
}
/* Sets the given tag attribute or adds a new attribute if not found. A value
of NULL will remove the specified attribute. Returns the tag given */
SWITCH_DECLARE(switch_xml_t) switch_xml_set_attr_d_buf(switch_xml_t xml, const char *name, const char *value)
{
if (!xml) return NULL;
return switch_xml_set_attr(switch_xml_set_flag(xml, SWITCH_XML_DUP), strdup(name), strdup(value));
}
/* sets a flag for the given tag and returns the tag */
SWITCH_DECLARE(switch_xml_t) switch_xml_set_flag(switch_xml_t xml, switch_xml_flag_t flag)
{