mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
use g_autoptr for all xmlBuffers
AUTOPTR_CLEANUP_FUNC is set to xmlBufferFree() in util/virxml.h (This
is actually new - added accidentally (but fortunately harmlessly!) in
commit 257aba2daf
. 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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
b7a92bce07
commit
a726feb693
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
@ -697,8 +697,8 @@ virVMXConvertToUTF8(const char *encoding, const char *string)
|
||||
{
|
||||
char *result = NULL;
|
||||
xmlCharEncodingHandlerPtr handler;
|
||||
xmlBufferPtr input = NULL;
|
||||
xmlBufferPtr utf8 = NULL;
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user