Signed-off-by: Laine Stump <laine(a)redhat.com>
---
src/util/virbitmap.c | 4 ++--
src/util/vircommand.c | 3 +--
src/util/virconf.c | 5 ++---
src/util/virdnsmasq.c | 6 ++----
src/util/virfile.c | 2 +-
src/util/virfilecache.c | 2 +-
src/util/virfirewall.c | 2 +-
src/util/virlog.c | 5 ++---
src/util/virnetdevip.c | 3 +--
src/util/virpidfile.c | 2 +-
src/util/virqemu.c | 3 +--
src/util/virresctrl.c | 10 +++-------
src/util/virsocketaddr.c | 3 +--
src/util/virstoragefile.c | 2 +-
src/util/virstring.c | 4 ++--
src/util/virsysinfo.c | 4 ++--
src/util/virsystemd.c | 4 ++--
src/util/viruri.c | 2 +-
src/util/virxml.c | 3 +--
19 files changed, 28 insertions(+), 41 deletions(-)
diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
index d38a2dd7e9..60fd8491dd 100644
--- a/src/util/virbitmap.c
+++ b/src/util/virbitmap.c
@@ -345,7 +345,7 @@ virBitmapToString(virBitmapPtr bitmap,
bool prefix,
bool trim)
{
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
size_t sz;
size_t len;
size_t diff;
@@ -404,7 +404,7 @@ virBitmapToString(virBitmapPtr bitmap,
char *
virBitmapFormat(virBitmapPtr bitmap)
{
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
bool first = true;
int start, cur, prev;
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index aae0ddb730..e21116b232 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -2080,7 +2080,7 @@ char *
virCommandToString(virCommandPtr cmd, bool linebreaks)
{
size_t i;
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
bool prevopt = false;
/* Cannot assume virCommandRun will be called; so report the error
@@ -2101,7 +2101,6 @@ virCommandToString(virCommandPtr cmd, bool linebreaks)
char *eq = strchr(cmd->env[i], '=');
if (!eq) {
- virBufferFreeAndReset(&buf);
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("invalid use of command API"));
return NULL;
diff --git a/src/util/virconf.c b/src/util/virconf.c
index f79024f07a..77ca3f9b79 100644
--- a/src/util/virconf.c
+++ b/src/util/virconf.c
@@ -1419,7 +1419,7 @@ int virConfWalk(virConfPtr conf,
int
virConfWriteFile(const char *filename, virConfPtr conf)
{
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virConfEntryPtr cur;
int ret;
int fd;
@@ -1437,7 +1437,6 @@ virConfWriteFile(const char *filename, virConfPtr conf)
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fd < 0) {
- virBufferFreeAndReset(&buf);
virConfError(NULL, VIR_ERR_WRITE_FAILED, _("failed to open file"));
return -1;
}
@@ -1471,7 +1470,7 @@ virConfWriteFile(const char *filename, virConfPtr conf)
int
virConfWriteMem(char *memory, int *len, virConfPtr conf)
{
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virConfEntryPtr cur;
char *content;
unsigned int use;
diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c
index 818219fbeb..b22d4622d5 100644
--- a/src/util/virdnsmasq.c
+++ b/src/util/virdnsmasq.c
@@ -139,7 +139,7 @@ addnhostsNew(const char *name,
const char *config_dir)
{
dnsmasqAddnHostsfile *addnhostsfile;
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (VIR_ALLOC(addnhostsfile) < 0)
return NULL;
@@ -157,7 +157,6 @@ addnhostsNew(const char *name,
return addnhostsfile;
error:
- virBufferFreeAndReset(&buf);
addnhostsFree(addnhostsfile);
return NULL;
}
@@ -342,7 +341,7 @@ hostsfileNew(const char *name,
const char *config_dir)
{
dnsmasqHostsfile *hostsfile;
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (VIR_ALLOC(hostsfile) < 0)
return NULL;
@@ -359,7 +358,6 @@ hostsfileNew(const char *name,
return hostsfile;
error:
- virBufferFreeAndReset(&buf);
hostsfileFree(hostsfile);
return NULL;
}
diff --git a/src/util/virfile.c b/src/util/virfile.c
index c034df5931..213acdbcaa 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1303,7 +1303,7 @@ int
virBuildPathInternal(char **path, ...)
{
char *path_component = NULL;
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
va_list ap;
int ret = 0;
diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c
index 2162917b11..195587e6bd 100644
--- a/src/util/virfilecache.c
+++ b/src/util/virfilecache.c
@@ -101,7 +101,7 @@ virFileCacheGetFileName(virFileCachePtr cache,
const char *name)
{
g_autofree char *namehash = NULL;
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, name, &namehash) < 0)
return NULL;
diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c
index 22760e6389..12905165d4 100644
--- a/src/util/virfirewall.c
+++ b/src/util/virfirewall.c
@@ -641,7 +641,7 @@ static char *
virFirewallRuleToString(virFirewallRulePtr rule)
{
const char *bin = virFirewallLayerCommandTypeToString(rule->layer);
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
size_t i;
virBufferAdd(&buf, bin, -1);
diff --git a/src/util/virlog.c b/src/util/virlog.c
index 2c18eeed03..dabfe7e501 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -1071,7 +1071,7 @@ char *
virLogGetFilters(void)
{
size_t i;
- virBuffer filterbuf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) filterbuf = VIR_BUFFER_INITIALIZER;
virLogLock();
for (i = 0; i < virLogNbFilters; i++) {
@@ -1098,7 +1098,7 @@ char *
virLogGetOutputs(void)
{
size_t i;
- virBuffer outputbuf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) outputbuf = VIR_BUFFER_INITIALIZER;
virLogLock();
for (i = 0; i < virLogNbOutputs; i++) {
@@ -1131,7 +1131,6 @@ virLogGetOutputs(void)
error:
virLogUnlock();
- virBufferFreeAndReset(&outputbuf);
return NULL;
}
diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
index cb624c7eec..ba9e567e5a 100644
--- a/src/util/virnetdevip.c
+++ b/src/util/virnetdevip.c
@@ -660,7 +660,7 @@ virNetDevIPCheckIPv6Forwarding(void)
}
if (!valid) {
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
for (i = 0; i < data.ndevices; i++) {
virBufferAdd(&buf, data.devices[i], -1);
if (i < data.ndevices - 1)
@@ -672,7 +672,6 @@ virNetDevIPCheckIPv6Forwarding(void)
"RA routes without accept_ra set to 2 is likely to cause
"
"routes loss. Interfaces to look at: %s"),
virBufferCurrentContent(&buf));
- virBufferFreeAndReset(&buf);
}
cleanup:
diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c
index 1a6fbdc552..895eb83ea9 100644
--- a/src/util/virpidfile.c
+++ b/src/util/virpidfile.c
@@ -42,7 +42,7 @@ VIR_LOG_INIT("util.pidfile");
char *virPidFileBuildPath(const char *dir, const char* name)
{
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(&buf, "%s", dir);
virBufferEscapeString(&buf, "/%s.pid", name);
diff --git a/src/util/virqemu.c b/src/util/virqemu.c
index 321ddeb7e3..52f3a2ca12 100644
--- a/src/util/virqemu.c
+++ b/src/util/virqemu.c
@@ -360,7 +360,7 @@ virQEMUBuildObjectCommandlineFromJSON(virBufferPtr buf,
char *
virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr srcdef)
{
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
char *ret = NULL;
if (virQEMUBuildCommandLineJSON(srcdef, &buf, NULL, false,
@@ -370,7 +370,6 @@ virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr srcdef)
ret = virBufferContentAndReset(&buf);
cleanup:
- virBufferFreeAndReset(&buf);
return ret;
}
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index e17f6bd1bd..33044da3a1 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -1587,20 +1587,16 @@ virResctrlAllocFormatCache(virResctrlAllocPtr alloc,
char *
virResctrlAllocFormat(virResctrlAllocPtr alloc)
{
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (!alloc)
return NULL;
- if (virResctrlAllocFormatCache(alloc, &buf) < 0) {
- virBufferFreeAndReset(&buf);
+ if (virResctrlAllocFormatCache(alloc, &buf) < 0)
return NULL;
- }
- if (virResctrlAllocMemoryBandwidthFormat(alloc, &buf) < 0) {
- virBufferFreeAndReset(&buf);
+ if (virResctrlAllocMemoryBandwidthFormat(alloc, &buf) < 0)
return NULL;
- }
return virBufferContentAndReset(&buf);
}
diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index a858a69204..0fda8e101b 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -1263,7 +1263,7 @@ virSocketAddrPTRDomain(const virSocketAddr *addr,
unsigned int prefix,
char **ptr)
{
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
size_t i;
int ret = -1;
@@ -1303,7 +1303,6 @@ virSocketAddrPTRDomain(const virSocketAddr *addr,
ret = 0;
cleanup:
- virBufferFreeAndReset(&buf);
return ret;
unsupported:
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index a6357abb08..274883c4bd 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -4255,7 +4255,7 @@ virStorageFileCanonicalizeFormatPath(char **components,
bool beginSlash,
bool beginDoubleSlash)
{
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
size_t i;
char *ret = NULL;
diff --git a/src/util/virstring.c b/src/util/virstring.c
index e9e792f3bf..2d7ddc4676 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -148,7 +148,7 @@ char *virStringListJoin(const char **strings,
const char *delim)
{
char *ret;
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
while (*strings) {
virBufferAdd(&buf, *strings, -1);
if (*(strings+1))
@@ -1069,7 +1069,7 @@ virStringReplace(const char *haystack,
const char *oldneedle,
const char *newneedle)
{
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
const char *tmp1, *tmp2;
size_t oldneedlelen = strlen(oldneedle);
size_t newneedlelen = strlen(newneedle);
diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index db84339bda..dbca99c1ef 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -1573,8 +1573,8 @@ virSysinfoFormatFWCfg(virBufferPtr buf,
int
virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
{
- virBuffer attrBuf = VIR_BUFFER_INITIALIZER;
- virBuffer childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
+ g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf);
const char *type = virSysinfoTypeToString(def->type);
if (!type) {
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 1d41ed34f7..0d5a54130d 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -100,7 +100,7 @@ char *virSystemdMakeScopeName(const char *name,
const char *drivername,
bool legacy_behaviour)
{
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virBufferAddLit(&buf, "machine-");
if (legacy_behaviour) {
@@ -116,7 +116,7 @@ char *virSystemdMakeScopeName(const char *name,
char *virSystemdMakeSliceName(const char *partition)
{
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
if (*partition == '/')
partition++;
diff --git a/src/util/viruri.c b/src/util/viruri.c
index 5fa0a6f0c8..492454a3df 100644
--- a/src/util/viruri.c
+++ b/src/util/viruri.c
@@ -252,7 +252,7 @@ virURIFormat(virURIPtr uri)
char *virURIFormatParams(virURIPtr uri)
{
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
size_t i;
bool amp = false;
diff --git a/src/util/virxml.c b/src/util/virxml.c
index 848d549a8b..e9ea9fe1a4 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -682,8 +682,7 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED, ...)
const xmlChar *cur, *base;
unsigned int n, col; /* GCC warns if signed, because compared with sizeof()
*/
int domcode = VIR_FROM_XML;
-
- virBuffer buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
char *contextstr = NULL;
char *pointerstr = NULL;
--
2.25.4