[njs] XML: fixed memory leaks in node.$tags set handler.

Dmitry Volyntsev xeioex at nginx.com
Wed Mar 1 04:37:13 UTC 2023


details:   https://hg.nginx.org/njs/rev/7197f860de2f
branches:  
changeset: 2060:7197f860de2f
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Feb 28 20:34:38 2023 -0800
description:
XML: fixed memory leaks in node.$tags set handler.

If xmlAddChild() failed the node pointer leaked,
if xmlReconciliateNs() failed the copy pointer leaked.

diffstat:

 external/njs_xml_module.c |  8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diffs (32 lines):

diff -r 688c4b1d9626 -r 7197f860de2f external/njs_xml_module.c
--- a/external/njs_xml_module.c	Tue Feb 28 20:34:31 2023 -0800
+++ b/external/njs_xml_module.c	Tue Feb 28 20:34:38 2023 -0800
@@ -1211,7 +1211,7 @@ njs_xml_node_tags_handler(njs_vm_t *vm, 
 {
     size_t       size;
     int64_t      i, length;
-    xmlNode      *node, *copy;
+    xmlNode      *node, *rnode, *copy;
     njs_int_t    ret;
     njs_value_t  *push;
     njs_opaque_value_t  *start;
@@ -1303,8 +1303,8 @@ njs_xml_node_tags_handler(njs_vm_t *vm, 
             goto error;
         }
 
-        node = xmlAddChild(copy, node);
-        if (njs_slow_path(node == NULL)) {
+        rnode = xmlAddChild(copy, node);
+        if (njs_slow_path(rnode == NULL)) {
             njs_vm_error(vm, "xmlAddChild() failed");
             xmlFreeNode(node);
             goto error;
@@ -1313,7 +1313,7 @@ njs_xml_node_tags_handler(njs_vm_t *vm, 
         ret = xmlReconciliateNs(current->doc, copy);
         if (njs_slow_path(ret == -1)) {
             njs_vm_error(vm, "xmlReconciliateNs() failed");
-            return NJS_ERROR;
+            goto error;
         }
     }
 


More information about the nginx-devel mailing list