tools: 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 19:40:16 -04:00
parent 25c23b95b6
commit ecc4ee2c42
9 changed files with 42 additions and 53 deletions

View File

@ -235,7 +235,7 @@ cmdCheckpointCreateAs(vshControl *ctl,
char *buffer = NULL;
const char *name = NULL;
const char *desc = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
unsigned int flags = 0;
const vshCmdOpt *opt = NULL;
@ -278,7 +278,6 @@ cmdCheckpointCreateAs(vshControl *ctl,
ret = virshCheckpointCreate(ctl, dom, buffer, flags, NULL);
cleanup:
virBufferFreeAndReset(&buf);
VIR_FREE(buffer);
virshDomainFree(dom);

View File

@ -2413,7 +2413,7 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
}
for (j = 0; j < iface->naddrs; j++) {
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
switch (iface->addrs[j].type) {
case VIR_IP_ADDR_TYPE_IPV4:
@ -2442,7 +2442,6 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd)
vshPrint(ctl, " %-10s %-17s %s\n",
"-", "-", ip_addr_str);
virBufferFreeAndReset(&buf);
VIR_FREE(ip_addr_str);
}
}

View File

@ -575,7 +575,7 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
int ret;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
const char *stype = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
char *xml = NULL;
struct stat st;
bool current = vshCommandOptBool(cmd, "current");
@ -778,7 +778,6 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
cleanup:
VIR_FREE(xml);
virshDomainFree(dom);
virBufferFreeAndReset(&buf);
return functionReturn;
}
@ -905,7 +904,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
virDomainNetType typ;
int ret;
bool functionReturn = false;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
char *xml = NULL;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
bool current = vshCommandOptBool(cmd, "current");
@ -1091,7 +1090,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
cleanup:
VIR_FREE(xml);
virshDomainFree(dom);
virBufferFreeAndReset(&buf);
return functionReturn;
}
@ -2412,7 +2410,7 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd)
}
if (!xmlstr) {
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, "<disk type='%s'>\n",
blockdev ? "block" : "file");
virBufferAdjustIndent(&buf, 2);
@ -8490,7 +8488,7 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd)
char *tmp = NULL;
char *tmpstr;
const vshCmdOpt *opt = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
bool ret = false;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
@ -9628,7 +9626,7 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd)
g_autoptr(virJSONValue) resultjson = NULL;
unsigned int flags = 0;
const vshCmdOpt *opt = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
bool pretty = vshCommandOptBool(cmd, "pretty");
bool returnval = vshCommandOptBool(cmd, "return-value");
virJSONValuePtr formatjson;
@ -9942,7 +9940,7 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd)
int judge = 0;
unsigned int flags = 0;
const vshCmdOpt *opt = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virJSONValuePtr pretty = NULL;
dom = virshCommandOptDomain(ctl, cmd, NULL);
@ -11492,7 +11490,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL;
virDomainPtr dom;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
bool ret = false;
char *xpath = NULL;
char *listen_addr = NULL;
@ -13188,7 +13186,7 @@ virshEventGenericPrint(virConnectPtr conn G_GNUC_UNUSED,
virDomainPtr dom,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event '%s' for domain %s\n"),
((virshDomEventData *) opaque)->cb->name,
@ -13203,7 +13201,7 @@ virshEventLifecyclePrint(virConnectPtr conn G_GNUC_UNUSED,
int detail,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'lifecycle' for domain %s: %s %s\n"),
virDomainGetName(dom),
@ -13218,7 +13216,7 @@ virshEventRTCChangePrint(virConnectPtr conn G_GNUC_UNUSED,
long long utcoffset,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'rtc-change' for domain %s: %lld\n"),
virDomainGetName(dom),
@ -13232,7 +13230,7 @@ virshEventWatchdogPrint(virConnectPtr conn G_GNUC_UNUSED,
int action,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'watchdog' for domain %s: %s\n"),
virDomainGetName(dom),
@ -13248,7 +13246,7 @@ virshEventIOErrorPrint(virConnectPtr conn G_GNUC_UNUSED,
int action,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'io-error' for domain %s: %s (%s) %s\n"),
virDomainGetName(dom),
@ -13268,7 +13266,7 @@ virshEventGraphicsPrint(virConnectPtr conn G_GNUC_UNUSED,
const virDomainEventGraphicsSubject *subject,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
size_t i;
virBufferAsprintf(&buf, _("event 'graphics' for domain %s: "
@ -13299,7 +13297,7 @@ virshEventIOErrorReasonPrint(virConnectPtr conn G_GNUC_UNUSED,
const char *reason,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'io-error-reason' for domain %s: "
"%s (%s) %s due to %s\n"),
@ -13319,7 +13317,7 @@ virshEventBlockJobPrint(virConnectPtr conn G_GNUC_UNUSED,
int status,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event '%s' for domain %s: %s for %s %s\n"),
((virshDomEventData *) opaque)->cb->name,
@ -13339,7 +13337,7 @@ virshEventDiskChangePrint(virConnectPtr conn G_GNUC_UNUSED,
int reason,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'disk-change' for domain %s disk %s: "
"%s -> %s: %s\n"),
@ -13358,7 +13356,7 @@ virshEventTrayChangePrint(virConnectPtr conn G_GNUC_UNUSED,
int reason,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'tray-change' for domain %s disk %s: %s\n"),
virDomainGetName(dom),
@ -13384,7 +13382,7 @@ virshEventBalloonChangePrint(virConnectPtr conn G_GNUC_UNUSED,
unsigned long long actual,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'balloon-change' for domain %s: %lluKiB\n"),
virDomainGetName(dom),
@ -13398,7 +13396,7 @@ virshEventDeviceRemovedPrint(virConnectPtr conn G_GNUC_UNUSED,
const char *alias,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'device-removed' for domain %s: %s\n"),
virDomainGetName(dom),
@ -13412,7 +13410,7 @@ virshEventDeviceAddedPrint(virConnectPtr conn G_GNUC_UNUSED,
const char *alias,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'device-added' for domain %s: %s\n"),
virDomainGetName(dom),
@ -13427,7 +13425,7 @@ virshEventTunablePrint(virConnectPtr conn G_GNUC_UNUSED,
int nparams,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
size_t i;
char *value;
@ -13465,7 +13463,7 @@ virshEventAgentLifecyclePrint(virConnectPtr conn G_GNUC_UNUSED,
int reason,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'agent-lifecycle' for domain %s: state: "
"'%s' reason: '%s'\n"),
@ -13481,7 +13479,7 @@ virshEventMigrationIterationPrint(virConnectPtr conn G_GNUC_UNUSED,
int iteration,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'migration-iteration' for domain %s: "
"iteration: '%d'\n"),
@ -13498,7 +13496,7 @@ virshEventJobCompletedPrint(virConnectPtr conn G_GNUC_UNUSED,
int nparams,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
size_t i;
char *value;
@ -13521,7 +13519,7 @@ virshEventDeviceRemovalFailedPrint(virConnectPtr conn G_GNUC_UNUSED,
const char *alias,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'device-removal-failed' for domain %s: %s\n"),
virDomainGetName(dom),
@ -13543,7 +13541,7 @@ virshEventMetadataChangePrint(virConnectPtr conn G_GNUC_UNUSED,
const char *nsuri,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'metadata-change' for domain %s: %s %s\n"),
virDomainGetName(dom),
@ -13562,7 +13560,7 @@ virshEventBlockThresholdPrint(virConnectPtr conn G_GNUC_UNUSED,
unsigned long long excess,
void *opaque)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, _("event 'block-threshold' for domain %s: "
"dev: %s(%s) %llu %llu\n"),
@ -14153,7 +14151,7 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
for (i = 0; i < ninfos; i++) {
virBuffer targetsBuff = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) targetsBuff = VIR_BUFFER_INITIALIZER;
g_autofree char *targets = NULL;
for (j = 0; j < info[i]->ndevAlias; j++)

View File

@ -325,7 +325,7 @@ virshBuildPoolXML(vshControl *ctl,
*adapterWwnn = NULL, *adapterWwpn = NULL, *secretUUID = NULL,
*adapterParentWwnn = NULL, *adapterParentWwpn = NULL,
*adapterParentFabricWwn = NULL, *protoVer = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
VSH_EXCLUSIVE_OPTIONS("secret-usage", "secret-uuid");
@ -421,7 +421,6 @@ virshBuildPoolXML(vshControl *ctl,
return true;
cleanup:
virBufferFreeAndReset(&buf);
return false;
}
@ -1450,11 +1449,10 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd G_GNUC_UNUSED)
if (host) {
const char *port = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (vshCommandOptStringReq(ctl, cmd, "port", &port) < 0) {
vshError(ctl, "%s", _("missing argument"));
virBufferFreeAndReset(&buf);
return false;
}
virBufferAddLit(&buf, "<source>\n");

View File

@ -585,7 +585,7 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
int usageType = virSecretGetUsageType(sec);
const char *usageStr = virSecretUsageTypeToString(usageType);
char uuid[VIR_UUID_STRING_BUFLEN];
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_autofree char *usage = NULL;
if (virSecretGetUUIDString(sec, uuid) < 0) {

View File

@ -395,7 +395,7 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
const char *name = NULL;
const char *desc = NULL;
const char *memspec = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
unsigned int flags = VIR_DOMAIN_SNAPSHOT_CREATE_VALIDATE;
const vshCmdOpt *opt = NULL;
@ -456,7 +456,6 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
ret = virshSnapshotCreate(ctl, dom, buffer, flags, NULL);
cleanup:
virBufferFreeAndReset(&buf);
VIR_FREE(buffer);
virshDomainFree(dom);

View File

@ -226,7 +226,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
const char *name, *capacityStr = NULL, *allocationStr = NULL, *format = NULL;
const char *snapshotStrVol = NULL, *snapshotStrFormat = NULL;
unsigned long long capacity, allocation = 0;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
unsigned long flags = 0;
virshControlPtr priv = ctl->privData;
bool ret = false;
@ -356,7 +356,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
ret = true;
cleanup:
virBufferFreeAndReset(&buf);
if (vol)
virStorageVolFree(vol);
virStoragePoolFree(pool);

View File

@ -368,7 +368,7 @@ vshTablePrint(vshTablePtr table, bool header)
size_t j;
size_t *maxwidths;
size_t **widths;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
char *ret = NULL;
if (VIR_ALLOC_N(maxwidths, table->rows[0]->ncells))

View File

@ -2183,7 +2183,7 @@ void
vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format,
va_list ap)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
char *str = NULL;
size_t len;
const char *lvl = "";
@ -2241,7 +2241,6 @@ vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format,
error:
vshCloseLogFile(ctl);
vshError(ctl, "%s", _("failed to write the log file"));
virBufferFreeAndReset(&buf);
VIR_FREE(str);
}
@ -2531,13 +2530,12 @@ vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque,
int num_devices, int devid)
{
int ret;
virBuffer indent = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) indent = VIR_BUFFER_INITIALIZER;
ret = vshTreePrintInternal(ctl, lookup, opaque, num_devices,
devid, devid, true, &indent);
if (ret < 0)
vshError(ctl, "%s", _("Failed to complete tree listing"));
virBufferFreeAndReset(&indent);
return ret;
}
@ -2806,7 +2804,7 @@ vshReadlineParse(const char *text, int state)
if (ret &&
!rl_completion_quote_character) {
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferEscapeShell(&buf, ret);
VIR_FREE(ret);
ret = virBufferContentAndReset(&buf);
@ -3217,7 +3215,7 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd)
int count = 0;
const vshCmdOpt *opt = NULL;
char *arg;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (vshCommandOptBool(cmd, "shell"))
shell = true;
@ -3228,7 +3226,7 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd)
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
char *str;
virBuffer xmlbuf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) xmlbuf = VIR_BUFFER_INITIALIZER;
arg = opt->data;
@ -3366,7 +3364,7 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd)
const char *arg = "";
const vshCmdOpt *opt = NULL;
char **matches = NULL, **iter;
virBuffer buf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (vshCommandOptStringQuiet(ctl, cmd, "string", &arg) <= 0)
goto cleanup;
@ -3406,7 +3404,6 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd)
ret = true;
cleanup:
virBufferFreeAndReset(&buf);
virStringListFree(matches);
return ret;
}