conf: use g_auto() for all virBuffers

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Laine Stump 2020-07-02 22:19:01 -04:00
parent ecc4ee2c42
commit 0e3dc7c5c5
19 changed files with 39 additions and 61 deletions

View File

@ -705,7 +705,7 @@ virCapabilitiesDomainDataLookupInternal(virCapsPtr caps,
/* XXX check default_emulator, see how it uses this */
if (!foundguest) {
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (ostype)
virBufferAsprintf(&buf, "ostype=%s ",
virDomainOSTypeToString(ostype));
@ -725,7 +725,6 @@ virCapabilitiesDomainDataLookupInternal(virCapsPtr caps,
virReportError(VIR_ERR_INVALID_ARG,
_("could not find capabilities for %s"),
virBufferCurrentContent(&buf));
virBufferFreeAndReset(&buf);
return ret;
}
@ -901,7 +900,7 @@ virCapabilitiesFormatResctrlMonitor(virBufferPtr buf,
virResctrlInfoMonPtr monitor)
{
size_t i = 0;
virBuffer childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
/* monitor not supported, no capability */
if (!monitor)
@ -1335,7 +1334,7 @@ virCapabilitiesFormatStoragePoolXML(virCapsStoragePoolPtr *pools,
char *
virCapabilitiesFormatXML(virCapsPtr caps)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAddLit(&buf, "<capabilities>\n\n");
virBufferAdjustIndent(&buf, 2);
@ -1353,7 +1352,6 @@ virCapabilitiesFormatXML(virCapsPtr caps)
return virBufferContentAndReset(&buf);
error:
virBufferFreeAndReset(&buf);
return NULL;
}

View File

@ -502,7 +502,7 @@ virDomainCheckpointDefFormat(virDomainCheckpointDefPtr def,
virDomainXMLOptionPtr xmlopt,
unsigned int flags)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virCheckFlags(VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE |
VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN |

View File

@ -668,7 +668,7 @@ char *
virCPUDefFormat(virCPUDefPtr def,
virDomainNumaPtr numa)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (virCPUDefFormatBufFull(&buf, def, numa) < 0)
goto cleanup;
@ -676,7 +676,6 @@ virCPUDefFormat(virCPUDefPtr def,
return virBufferContentAndReset(&buf);
cleanup:
virBufferFreeAndReset(&buf);
return NULL;
}
@ -687,8 +686,8 @@ virCPUDefFormatBufFull(virBufferPtr buf,
virDomainNumaPtr numa)
{
int ret = -1;
virBuffer attributeBuf = VIR_BUFFER_INITIALIZER;
virBuffer childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
g_auto(virBuffer) attributeBuf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
if (!def)
return 0;
@ -755,8 +754,6 @@ virCPUDefFormatBufFull(virBufferPtr buf,
ret = 0;
cleanup:
virBufferFreeAndReset(&attributeBuf);
virBufferFreeAndReset(&childrenBuf);
return ret;
}

View File

@ -1941,7 +1941,7 @@ virDomainUSBAddressPortFormatBuf(virBufferPtr buf,
static char * ATTRIBUTE_NONNULL(1)
virDomainUSBAddressPortFormat(unsigned int *port)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virDomainUSBAddressPortFormatBuf(&buf, port);
return virBufferContentAndReset(&buf);
}

View File

@ -596,7 +596,7 @@ virDomainCapsFormatFeatures(const virDomainCaps *caps,
char *
virDomainCapsFormat(const virDomainCaps *caps)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
const char *virttype_str = virDomainVirtTypeToString(caps->virttype);
const char *arch_str = virArchToString(caps->arch);

View File

@ -25264,7 +25264,7 @@ static int
virDomainDiskDefFormatIotune(virBufferPtr buf,
virDomainDiskDefPtr disk)
{
virBuffer childBuf = VIR_BUFFER_INIT_CHILD(buf);
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
FORMAT_IOTUNE(total_bytes_sec);
FORMAT_IOTUNE(read_bytes_sec);
@ -25309,7 +25309,7 @@ static int
virDomainDiskDefFormatDriver(virBufferPtr buf,
virDomainDiskDefPtr disk)
{
virBuffer driverBuf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) driverBuf = VIR_BUFFER_INITIALIZER;
virBufferEscapeString(&driverBuf, " name='%s'", virDomainDiskGetDriver(disk));
@ -26293,7 +26293,7 @@ static int
virDomainVirtioNetGuestOptsFormat(char **outstr,
virDomainNetDefPtr def)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (def->driver.virtio.guest.csum) {
virBufferAsprintf(&buf, "csum='%s' ",
virTristateSwitchTypeToString(def->driver.virtio.guest.csum));
@ -26325,7 +26325,7 @@ static int
virDomainVirtioNetHostOptsFormat(char **outstr,
virDomainNetDefPtr def)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (def->driver.virtio.host.csum) {
virBufferAsprintf(&buf, "csum='%s' ",
virTristateSwitchTypeToString(def->driver.virtio.host.csum));
@ -26365,7 +26365,7 @@ static int
virDomainVirtioNetDriverFormat(char **outstr,
virDomainNetDefPtr def)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (def->driver.virtio.name) {
virBufferAsprintf(&buf, " name='%s'",
virDomainNetBackendTypeToString(def->driver.virtio.name));
@ -29997,7 +29997,7 @@ virDomainDefFormat(virDomainDefPtr def,
virDomainXMLOptionPtr xmlopt,
unsigned int flags)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virCheckFlags(VIR_DOMAIN_DEF_FORMAT_COMMON_FLAGS, NULL);
if (virDomainDefFormatInternal(def, xmlopt, &buf, flags) < 0)

View File

@ -1122,11 +1122,10 @@ virInterfaceDefDevFormat(virBufferPtr buf,
char *
virInterfaceDefFormat(const virInterfaceDef *def)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (virInterfaceDefDevFormat(&buf, def, VIR_INTERFACE_TYPE_LAST) < 0) {
virBufferFreeAndReset(&buf);
if (virInterfaceDefDevFormat(&buf, def, VIR_INTERFACE_TYPE_LAST) < 0)
return NULL;
}
return virBufferContentAndReset(&buf);
}

View File

@ -2718,7 +2718,7 @@ virNetworkDefFormat(const virNetworkDef *def,
virNetworkXMLOptionPtr xmlopt,
unsigned int flags)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (virNetworkDefFormatBuf(&buf, def, xmlopt, flags) < 0)
goto error;
@ -2726,7 +2726,6 @@ virNetworkDefFormat(const virNetworkDef *def,
return virBufferContentAndReset(&buf);
error:
virBufferFreeAndReset(&buf);
return NULL;
}

View File

@ -520,7 +520,7 @@ virNodeDeviceCapMdevDefFormat(virBufferPtr buf,
char *
virNodeDeviceDefFormat(const virNodeDeviceDef *def)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virNodeDevCapsDefPtr caps;
size_t i = 0;

View File

@ -948,7 +948,7 @@ printTCPFlags(virBufferPtr buf,
char *
virNWFilterPrintTCPFlags(uint8_t flags)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
printTCPFlags(&buf, flags);
return virBufferContentAndReset(&buf);
}
@ -2561,7 +2561,7 @@ virNWFilterIsAllowedChain(const char *chainname)
virNWFilterChainSuffixType i;
const char *name;
char *msg;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
bool printed = false;
if (!virNWFilterIsValidChainName(chainname))
@ -3044,7 +3044,7 @@ virNWFilterEntryFormat(virBufferPtr buf,
char *
virNWFilterDefFormat(const virNWFilterDef *def)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
char uuid[VIR_UUID_STRING_BUFLEN];
size_t i;
@ -3071,7 +3071,6 @@ virNWFilterDefFormat(const virNWFilterDef *def)
return virBufferContentAndReset(&buf);
err_exit:
virBufferFreeAndReset(&buf);
return NULL;
}

View File

@ -277,7 +277,7 @@ virSecretDefFormatUsage(virBufferPtr buf,
char *
virSecretDefFormat(const virSecretDef *def)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
const unsigned char *uuid;
char uuidstr[VIR_UUID_STRING_BUFLEN];
@ -301,6 +301,5 @@ virSecretDefFormat(const virSecretDef *def)
return virBufferContentAndReset(&buf);
error:
virBufferFreeAndReset(&buf);
return NULL;
}

View File

@ -927,7 +927,7 @@ virDomainSnapshotDefFormat(const char *uuidstr,
virDomainXMLOptionPtr xmlopt,
unsigned int flags)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virCheckFlags(VIR_DOMAIN_SNAPSHOT_FORMAT_SECURE |
VIR_DOMAIN_SNAPSHOT_FORMAT_INTERNAL |

View File

@ -117,16 +117,14 @@ virStoragePoolCapsFormatPool(virBufferPtr buf,
char *
virStoragePoolCapsFormat(const virStoragePoolCaps *caps)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
size_t i;
virBufferAddLit(&buf, "<storagepoolCapabilities>\n");
virBufferAdjustIndent(&buf, 2);
for (i = 0; i < VIR_STORAGE_POOL_LAST; i++) {
if (virStoragePoolCapsFormatPool(&buf, i, caps) < 0) {
virBufferFreeAndReset(&buf);
if (virStoragePoolCapsFormatPool(&buf, i, caps) < 0)
return NULL;
}
}
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</storagepoolCapabilities>\n");

View File

@ -1223,7 +1223,7 @@ virStoragePoolDefFormatBuf(virBufferPtr buf,
char *
virStoragePoolDefFormat(virStoragePoolDefPtr def)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (virStoragePoolDefFormatBuf(&buf, def) < 0)
goto error;
@ -1231,7 +1231,6 @@ virStoragePoolDefFormat(virStoragePoolDefPtr def)
return virBufferContentAndReset(&buf);
error:
virBufferFreeAndReset(&buf);
return NULL;
}
@ -1594,7 +1593,7 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
virStorageVolDefPtr def)
{
virStorageVolOptionsPtr options;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
options = virStorageVolOptionsForPoolType(pool->type);
if (options == NULL)
@ -1663,7 +1662,6 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
return virBufferContentAndReset(&buf);
cleanup:
virBufferFreeAndReset(&buf);
return NULL;
}
@ -1686,7 +1684,7 @@ int
virStoragePoolSaveState(const char *stateFile,
virStoragePoolDefPtr def)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_autofree char *xml = NULL;
virBufferAddLit(&buf, "<poolstate>\n");
@ -1743,7 +1741,7 @@ char *
virStoragePoolSourceListFormat(virStoragePoolSourceListPtr def)
{
virStoragePoolOptionsPtr options;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
const char *type;
size_t i;
@ -1770,6 +1768,5 @@ virStoragePoolSourceListFormat(virStoragePoolSourceListPtr def)
return virBufferContentAndReset(&buf);
cleanup:
virBufferFreeAndReset(&buf);
return NULL;
}

View File

@ -815,7 +815,7 @@ virNetworkObjFormat(virNetworkObjPtr obj,
virNetworkXMLOptionPtr xmlopt,
unsigned int flags)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
char *classIdStr = virBitmapFormat(obj->classIdMap);
size_t i;
@ -843,7 +843,6 @@ virNetworkObjFormat(virNetworkObjPtr obj,
return virBufferContentAndReset(&buf);
error:
virBufferFreeAndReset(&buf);
return NULL;
}

View File

@ -324,12 +324,10 @@ virNetworkPortDefParseFile(const char *filename)
char *
virNetworkPortDefFormat(const virNetworkPortDef *def)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (virNetworkPortDefFormatBuf(&buf, def) < 0) {
virBufferFreeAndReset(&buf);
if (virNetworkPortDefFormatBuf(&buf, def) < 0)
return NULL;
}
return virBufferContentAndReset(&buf);
}

View File

@ -223,12 +223,10 @@ virNWFilterBindingDefParseFile(const char *filename)
char *
virNWFilterBindingDefFormat(const virNWFilterBindingDef *def)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (virNWFilterBindingDefFormatBuf(&buf, def) < 0) {
virBufferFreeAndReset(&buf);
if (virNWFilterBindingDefFormatBuf(&buf, def) < 0)
return NULL;
}
return virBufferContentAndReset(&buf);
}

View File

@ -284,16 +284,14 @@ virNWFilterBindingObjParseFile(const char *filename)
char *
virNWFilterBindingObjFormat(const virNWFilterBindingObj *obj)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAddLit(&buf, "<filterbindingstatus>\n");
virBufferAdjustIndent(&buf, 2);
if (virNWFilterBindingDefFormatBuf(&buf, obj->def) < 0) {
virBufferFreeAndReset(&buf);
if (virNWFilterBindingDefFormatBuf(&buf, obj->def) < 0)
return NULL;
}
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</filterbindingstatus>\n");

View File

@ -127,7 +127,7 @@ char *
virSaveCookieFormat(virObjectPtr obj,
virSaveCookieCallbacksPtr saveCookie)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (virSaveCookieFormatBuf(&buf, obj, saveCookie) < 0)
goto error;
@ -135,6 +135,5 @@ virSaveCookieFormat(virObjectPtr obj,
return virBufferContentAndReset(&buf);
error:
virBufferFreeAndReset(&buf);
return NULL;
}