1From f442a3290626a522b6e71c902a971859b15566f3 Mon Sep 17 00:00:00 2001 2From: Nick Wellnhofer <wellnhofer@aevum.de> 3Date: Sun, 30 Oct 2022 12:32:14 +0100 4Subject: [PATCH 02/28] xinclude: Fix more memory leaks in xmlXIncludeLoadDoc 5 6Reference: https://github.com/GNOME/libxml2/commit/f14529baf5315b3d77877fd1617b0e1f3df564d0 7Conflict: xinclude.c:<xmlXIncludeLoadDoc> 8--- 9 xinclude.c | 37 ++++++++++++++----------------------- 10 1 file changed, 14 insertions(+), 23 deletions(-) 11 12diff --git a/xinclude.c b/xinclude.c 13index 6ee58cb..cd1e1b1 100644 14--- a/xinclude.c 15+++ b/xinclude.c 16@@ -1417,9 +1417,10 @@ static int 17 xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) { 18 xmlDocPtr doc; 19 xmlURIPtr uri; 20- xmlChar *URL; 21+ xmlChar *URL = NULL; 22 xmlChar *fragment = NULL; 23 int i = 0; 24+ int ret = -1; 25 #ifdef LIBXML_XPTR_ENABLED 26 int saveFlags; 27 #endif 28@@ -1435,7 +1436,7 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) { 29 xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 30 XML_XINCLUDE_HREF_URI, 31 "invalid value URI %s\n", url); 32- return(-1); 33+ goto error; 34 } 35 if (uri->fragment != NULL) { 36 fragment = (xmlChar *) uri->fragment; 37@@ -1457,9 +1458,7 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) { 38 xmlXIncludeErr(ctxt, NULL, 39 XML_XINCLUDE_HREF_URI, 40 "invalid value URI %s\n", url); 41- if (fragment != NULL) 42- xmlFree(fragment); 43- return(-1); 44+ goto error; 45 } 46 47 /* 48@@ -1509,10 +1508,7 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) { 49 ctxt->parseFlags = saveFlags; 50 #endif 51 if (doc == NULL) { 52- xmlFree(URL); 53- if (fragment != NULL) 54- xmlFree(fragment); 55- return(-1); 56+ goto error; 57 } 58 ctxt->incTab[nr]->doc = doc; 59 /* 60@@ -1578,9 +1574,7 @@ loaded: 61 xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref, 62 XML_XINCLUDE_XPTR_FAILED, 63 "could not create XPointer context\n", NULL); 64- xmlFree(URL); 65- xmlFree(fragment); 66- return(-1); 67+ goto error; 68 } 69 xptr = xmlXPtrEval(fragment, xptrctxt); 70 if (xptr == NULL) { 71@@ -1589,9 +1583,7 @@ loaded: 72 "XPointer evaluation failed: #%s\n", 73 fragment); 74 xmlXPathFreeContext(xptrctxt); 75- xmlFree(URL); 76- xmlFree(fragment); 77- return(-1); 78+ goto error; 79 } 80 switch (xptr->type) { 81 case XPATH_UNDEFINED: 82@@ -1607,17 +1599,13 @@ loaded: 83 fragment); 84 xmlXPathFreeObject(xptr); 85 xmlXPathFreeContext(xptrctxt); 86- xmlFree(URL); 87- xmlFree(fragment); 88- return(-1); 89+ goto error; 90 case XPATH_NODESET: 91 if ((xptr->nodesetval == NULL) || 92 (xptr->nodesetval->nodeNr <= 0)) { 93 xmlXPathFreeObject(xptr); 94 xmlXPathFreeContext(xptrctxt); 95- xmlFree(URL); 96- xmlFree(fragment); 97- return(-1); 98+ goto error; 99 } 100 101 case XPATH_RANGE: 102@@ -1681,7 +1669,6 @@ loaded: 103 xmlXIncludeCopyXPointer(ctxt, ctxt->doc, doc, xptr); 104 xmlXPathFreeObject(xptr); 105 xmlXPathFreeContext(xptrctxt); 106- xmlFree(fragment); 107 } 108 #endif 109 110@@ -1777,8 +1764,12 @@ loaded: 111 xmlFreeDoc(ctxt->incTab[nr]->doc); 112 ctxt->incTab[nr]->doc = NULL; 113 } 114+ ret = 0; 115+ 116+error: 117 xmlFree(URL); 118- return(0); 119+ xmlFree(fragment); 120+ return(ret); 121 } 122 123 /** 124-- 1252.27.0 126 127