]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11785 [core, mod_commands] update XML API to fix scan-build false positive memory...
authorChris Rienzo <chris@signalwire.com>
Mon, 15 Apr 2019 22:08:20 +0000 (22:08 +0000)
committerAndrey Volk <andywolk@gmail.com>
Wed, 17 Jul 2019 16:21:57 +0000 (20:21 +0400)
src/include/switch_xml.h
src/mod/applications/mod_commands/mod_commands.c
src/switch_xml.c

index e8e2a2bf925ed34ffa2f821b8a3745e696787918..5ea600a55093fe506af9e8fcbb8856202d14a31b 100644 (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
index ef9d1bb88066d17414dfd8e7d217c3e535278a53..3ab5007ee3e0bf0f516f07728c0dd612edc1134f 100644 (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);
 
index 9229d9214b392589955746cb4d0d9818bf8a84f7..60004f29d616bf2f13682f35c061b3181216637c 100644 (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)
 {