1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-12-28 07:21:26 +03:00

malloc-fail: Fix memory leak in xmlXPathCacheNewNodeSet

Found with libFuzzer, see #344.
This commit is contained in:
Nick Wellnhofer 2023-02-26 16:09:50 +01:00
parent 4499143a87
commit 6f9604f0e3

15
xpath.c
View File

@ -2467,21 +2467,24 @@ xmlXPathCacheNewNodeSet(xmlXPathContextPtr ctxt, xmlNodePtr val)
(cache->miscObjs->number != 0))
{
xmlXPathObjectPtr ret;
xmlNodeSetPtr set;
/*
* Fallback to misc-cache.
*/
set = xmlXPathNodeSetCreate(val);
if (set == NULL) {
ctxt->lastError.domain = XML_FROM_XPATH;
ctxt->lastError.code = XML_ERR_NO_MEMORY;
return(NULL);
}
ret = (xmlXPathObjectPtr)
cache->miscObjs->items[--cache->miscObjs->number];
ret->type = XPATH_NODESET;
ret->boolval = 0;
ret->nodesetval = xmlXPathNodeSetCreate(val);
if (ret->nodesetval == NULL) {
ctxt->lastError.domain = XML_FROM_XPATH;
ctxt->lastError.code = XML_ERR_NO_MEMORY;
return(NULL);
}
ret->nodesetval = set;
#ifdef XP_DEBUG_OBJ_USAGE
xmlXPathDebugObjUsageRequested(ctxt, XPATH_NODESET);
#endif