1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

malloc-fail: Fix memory leak after calling xmlXPathWrapString

Destroy the string in xmlXPathWrapString if the function fails. This is
somewhat dangerous but matches the expectations of users.

Found with libFuzzer, see #344.
This commit is contained in:
Nick Wellnhofer 2023-02-15 14:47:29 +01:00
parent 3dc645227e
commit d31a0e8e75

View File

@ -5322,6 +5322,8 @@ xmlXPathNewString(const xmlChar *val) {
* Wraps the @val string into an XPath object.
*
* Returns the newly created object.
*
* Frees @val in case of error.
*/
xmlXPathObjectPtr
xmlXPathWrapString (xmlChar *val) {
@ -5330,6 +5332,7 @@ xmlXPathWrapString (xmlChar *val) {
ret = (xmlXPathObjectPtr) xmlMalloc(sizeof(xmlXPathObject));
if (ret == NULL) {
xmlXPathErrMemory(NULL, "creating string object\n");
xmlFree(val);
return(NULL);
}
memset(ret, 0 , sizeof(xmlXPathObject));