diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 99b69aebb5..6a48af1fca 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -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, "\n\n"); virBufferAdjustIndent(&buf, 2); @@ -1353,7 +1352,6 @@ virCapabilitiesFormatXML(virCapsPtr caps) return virBufferContentAndReset(&buf); error: - virBufferFreeAndReset(&buf); return NULL; } diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 3405e8a3cc..89d117043b 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -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 | diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index a1514c2e14..12862a2986 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -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; } diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 2f9ff899d7..1068cbf1d2 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -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); } diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c index 0fa8aee78e..837b004334 100644 --- a/src/conf/domain_capabilities.c +++ b/src/conf/domain_capabilities.c @@ -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); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index abea23542a..37d4ccf955 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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) diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index be5e1133a2..76f7054721 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -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); } diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 4ebad1483c..99f11fdf05 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -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; } diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 78a537d0ea..c54015336a 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -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; diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 732c05ac89..3827c65462 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -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; } diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index 0ec9bce987..3960cf04ad 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -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; } diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index f73eeb06c7..9767592bfc 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -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 | diff --git a/src/conf/storage_capabilities.c b/src/conf/storage_capabilities.c index 1a3417f90b..cac238c4f2 100644 --- a/src/conf/storage_capabilities.c +++ b/src/conf/storage_capabilities.c @@ -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, "\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, "\n"); diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 5669b92f8d..7bc743887c 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -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, "\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; } diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index b2affaacd3..5d90dec2bc 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -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; } diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c index 2013e11dff..1db3dc69e2 100644 --- a/src/conf/virnetworkportdef.c +++ b/src/conf/virnetworkportdef.c @@ -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); } diff --git a/src/conf/virnwfilterbindingdef.c b/src/conf/virnwfilterbindingdef.c index 7d813353ef..f286bdd840 100644 --- a/src/conf/virnwfilterbindingdef.c +++ b/src/conf/virnwfilterbindingdef.c @@ -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); } diff --git a/src/conf/virnwfilterbindingobj.c b/src/conf/virnwfilterbindingobj.c index 7cfc2e9efa..584721f8b6 100644 --- a/src/conf/virnwfilterbindingobj.c +++ b/src/conf/virnwfilterbindingobj.c @@ -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, "\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, "\n"); diff --git a/src/conf/virsavecookie.c b/src/conf/virsavecookie.c index 7fc951afe2..429daf69be 100644 --- a/src/conf/virsavecookie.c +++ b/src/conf/virsavecookie.c @@ -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; }