1 Star 0 Fork 48

冉召宇/third_party_libxml2_1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
backport-xinclude-Fix-more-memory-leaks-in-xmlXIncludeLoadDoc.patch 3.29 KB
一键复制 编辑 原始数据 按行查看 历史
冉召宇 提交于 2024-04-25 19:13 . libxml2切openEuler7.0
From f442a3290626a522b6e71c902a971859b15566f3 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer <wellnhofer@aevum.de>
Date: Sun, 30 Oct 2022 12:32:14 +0100
Subject: [PATCH 02/28] xinclude: Fix more memory leaks in xmlXIncludeLoadDoc
Reference: https://github.com/GNOME/libxml2/commit/f14529baf5315b3d77877fd1617b0e1f3df564d0
Conflict: xinclude.c:<xmlXIncludeLoadDoc>
---
xinclude.c | 37 ++++++++++++++-----------------------
1 file changed, 14 insertions(+), 23 deletions(-)
diff --git a/xinclude.c b/xinclude.c
index 6ee58cb..cd1e1b1 100644
--- a/xinclude.c
+++ b/xinclude.c
@@ -1417,9 +1417,10 @@ static int
xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
xmlDocPtr doc;
xmlURIPtr uri;
- xmlChar *URL;
+ xmlChar *URL = NULL;
xmlChar *fragment = NULL;
int i = 0;
+ int ret = -1;
#ifdef LIBXML_XPTR_ENABLED
int saveFlags;
#endif
@@ -1435,7 +1436,7 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
XML_XINCLUDE_HREF_URI,
"invalid value URI %s\n", url);
- return(-1);
+ goto error;
}
if (uri->fragment != NULL) {
fragment = (xmlChar *) uri->fragment;
@@ -1457,9 +1458,7 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
xmlXIncludeErr(ctxt, NULL,
XML_XINCLUDE_HREF_URI,
"invalid value URI %s\n", url);
- if (fragment != NULL)
- xmlFree(fragment);
- return(-1);
+ goto error;
}
/*
@@ -1509,10 +1508,7 @@ xmlXIncludeLoadDoc(xmlXIncludeCtxtPtr ctxt, const xmlChar *url, int nr) {
ctxt->parseFlags = saveFlags;
#endif
if (doc == NULL) {
- xmlFree(URL);
- if (fragment != NULL)
- xmlFree(fragment);
- return(-1);
+ goto error;
}
ctxt->incTab[nr]->doc = doc;
/*
@@ -1578,9 +1574,7 @@ loaded:
xmlXIncludeErr(ctxt, ctxt->incTab[nr]->ref,
XML_XINCLUDE_XPTR_FAILED,
"could not create XPointer context\n", NULL);
- xmlFree(URL);
- xmlFree(fragment);
- return(-1);
+ goto error;
}
xptr = xmlXPtrEval(fragment, xptrctxt);
if (xptr == NULL) {
@@ -1589,9 +1583,7 @@ loaded:
"XPointer evaluation failed: #%s\n",
fragment);
xmlXPathFreeContext(xptrctxt);
- xmlFree(URL);
- xmlFree(fragment);
- return(-1);
+ goto error;
}
switch (xptr->type) {
case XPATH_UNDEFINED:
@@ -1607,17 +1599,13 @@ loaded:
fragment);
xmlXPathFreeObject(xptr);
xmlXPathFreeContext(xptrctxt);
- xmlFree(URL);
- xmlFree(fragment);
- return(-1);
+ goto error;
case XPATH_NODESET:
if ((xptr->nodesetval == NULL) ||
(xptr->nodesetval->nodeNr <= 0)) {
xmlXPathFreeObject(xptr);
xmlXPathFreeContext(xptrctxt);
- xmlFree(URL);
- xmlFree(fragment);
- return(-1);
+ goto error;
}
case XPATH_RANGE:
@@ -1681,7 +1669,6 @@ loaded:
xmlXIncludeCopyXPointer(ctxt, ctxt->doc, doc, xptr);
xmlXPathFreeObject(xptr);
xmlXPathFreeContext(xptrctxt);
- xmlFree(fragment);
}
#endif
@@ -1777,8 +1764,12 @@ loaded:
xmlFreeDoc(ctxt->incTab[nr]->doc);
ctxt->incTab[nr]->doc = NULL;
}
+ ret = 0;
+
+error:
xmlFree(URL);
- return(0);
+ xmlFree(fragment);
+ return(ret);
}
/**
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ran-zhao-yu/third_party_libxml2_1.git
git@gitee.com:ran-zhao-yu/third_party_libxml2_1.git
ran-zhao-yu
third_party_libxml2_1
third_party_libxml2_1
master

搜索帮助