AUTOPTR_CLEANUP_FUNC is set to xmlBufferFree() in util/virxml.h (This is actually new - added accidentally (but fortunately harmlessly!) in commit 257aba2dafe. I had added it along with the hunks in this patch, then decided to remove it and submit separately, but missed taking out the hunk in virxml.h) Signed-off-by: Laine Stump <laine@xxxxxxxxxx> --- src/conf/domain_conf.c | 4 +--- src/conf/network_conf.c | 4 +--- src/util/virxml.c | 12 +++--------- src/vmx/vmx.c | 10 +++------- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9d057f8c78..1916b51d38 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -29579,7 +29579,7 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def, def->description); if (def->metadata) { - xmlBufferPtr xmlbuf; + g_autoptr(xmlBuffer) xmlbuf = NULL; int oldIndentTreeOutput = xmlIndentTreeOutput; /* Indentation on output requires that we previously set @@ -29596,12 +29596,10 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def, if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, virBufferGetIndent(buf) / 2, 1) < 0) { - xmlBufferFree(xmlbuf); xmlIndentTreeOutput = oldIndentTreeOutput; goto error; } virBufferAsprintf(buf, "%s\n", (char *) xmlBufferContent(xmlbuf)); - xmlBufferFree(xmlbuf); xmlIndentTreeOutput = oldIndentTreeOutput; } diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 5b578f894c..4ebad1483c 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2508,7 +2508,7 @@ virNetworkDefFormatBuf(virBufferPtr buf, virBufferAsprintf(buf, "<uuid>%s</uuid>\n", uuidstr); if (def->metadata) { - xmlBufferPtr xmlbuf; + g_autoptr(xmlBuffer) xmlbuf = NULL; int oldIndentTreeOutput = xmlIndentTreeOutput; /* Indentation on output requires that we previously set @@ -2525,12 +2525,10 @@ virNetworkDefFormatBuf(virBufferPtr buf, if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, virBufferGetIndent(buf) / 2, 1) < 0) { - xmlBufferFree(xmlbuf); xmlIndentTreeOutput = oldIndentTreeOutput; return -1; } virBufferAsprintf(buf, "%s\n", (char *) xmlBufferContent(xmlbuf)); - xmlBufferFree(xmlbuf); xmlIndentTreeOutput = oldIndentTreeOutput; } diff --git a/src/util/virxml.c b/src/util/virxml.c index 02b59ea2f8..848d549a8b 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -953,8 +953,7 @@ char * virXMLNodeToString(xmlDocPtr doc, xmlNodePtr node) { - xmlBufferPtr xmlbuf = NULL; - char *ret = NULL; + g_autoptr(xmlBuffer) xmlbuf = NULL; if (!(xmlbuf = xmlBufferCreate())) { virReportOOMError(); @@ -964,15 +963,10 @@ virXMLNodeToString(xmlDocPtr doc, if (xmlNodeDump(xmlbuf, doc, node, 0, 1) == 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to convert the XML node tree")); - goto cleanup; + return NULL; } - ret = g_strdup((const char *)xmlBufferContent(xmlbuf)); - - cleanup: - xmlBufferFree(xmlbuf); - - return ret; + return g_strdup((const char *)xmlBufferContent(xmlbuf)); } diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index fa9766995c..67bbe27fde 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -697,8 +697,8 @@ virVMXConvertToUTF8(const char *encoding, const char *string) { char *result = NULL; xmlCharEncodingHandlerPtr handler; - xmlBufferPtr input; - xmlBufferPtr utf8; + g_autoptr(xmlBuffer) input = NULL; + g_autoptr(xmlBuffer) utf8 = NULL; handler = xmlFindCharEncodingHandler(encoding); @@ -720,14 +720,10 @@ virVMXConvertToUTF8(const char *encoding, const char *string) goto cleanup; } - result = (char *)utf8->content; - utf8->content = NULL; + result = (char *)g_steal_pointer(&utf8->content); cleanup: xmlCharEncCloseFunc(handler); - xmlBufferFree(input); - xmlBufferFree(utf8); - return result; } -- 2.25.4