mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
bhyve: use g_auto() for all virBuffers
In most cases this eliminates one or more calls to virBufferClearAndReset(), but even when it doesn't it's better because: 1) it makes the code more consistent, making it more likely that new contributors who are "learning by example" will to the right thing. 2) it protects against future modifications that might have otherwise needed to add a virBufferClearAndReset() 3) Currently some functions don't call virBufferClearAndReset() only because they're relying on some subordinate function to call it for them (e.g. bhyveConnectGetSysinfo() in this patch relies on virSysinfoFormat() to clear out the buffer when there is an error). I think this is sloppy behavior, and that the toplevel function that defines and initializes the buffer should be the function clearing it at the end. Signed-off-by: Laine Stump <laine@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
2020c6af8a
commit
2a15aa090d
@ -166,14 +166,15 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
|
||||
bhyveConnPtr driver,
|
||||
virCommandPtr cmd)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
virBuffer device = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
const char *disk_source;
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
|
||||
for (i = 0; i < def->ndisks; i++) {
|
||||
g_auto(virBuffer) device = VIR_BUFFER_INITIALIZER;
|
||||
virDomainDiskDefPtr disk = def->disks[i];
|
||||
|
||||
if (disk->bus != VIR_DOMAIN_DISK_BUS_SATA)
|
||||
continue;
|
||||
|
||||
@ -221,7 +222,6 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
|
||||
goto error;
|
||||
}
|
||||
virBufferAddBuffer(&buf, &device);
|
||||
virBufferFreeAndReset(&device);
|
||||
}
|
||||
|
||||
virCommandAddArg(cmd, "-s");
|
||||
@ -231,7 +231,6 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def,
|
||||
|
||||
ret = 0;
|
||||
error:
|
||||
virBufferFreeAndReset(&buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -378,7 +377,7 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
|
||||
virCommandPtr cmd,
|
||||
bool dryRun)
|
||||
{
|
||||
virBuffer opt = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) opt = VIR_BUFFER_INITIALIZER;
|
||||
virDomainGraphicsListenDefPtr glisten = NULL;
|
||||
bool escapeAddr;
|
||||
unsigned short port;
|
||||
@ -478,7 +477,6 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
|
||||
return 0;
|
||||
|
||||
error:
|
||||
virBufferFreeAndReset(&opt);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -765,7 +763,6 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
|
||||
char **devicesmap_out)
|
||||
{
|
||||
virDomainDiskDefPtr hdd, cd, userdef, diskdef;
|
||||
virBuffer devicemap;
|
||||
virCommandPtr cmd;
|
||||
unsigned int best_idx = UINT_MAX;
|
||||
size_t i;
|
||||
@ -773,8 +770,6 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
|
||||
if (def->os.bootloaderArgs != NULL)
|
||||
return virBhyveProcessBuildCustomLoaderCmd(def);
|
||||
|
||||
devicemap = (virBuffer)VIR_BUFFER_INITIALIZER;
|
||||
|
||||
/* Search disk list for CD or HDD device. We'll respect <boot order=''> if
|
||||
* present and otherwise pick the first CD or failing that HDD we come
|
||||
* across. */
|
||||
@ -809,6 +804,8 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
|
||||
VIR_DEBUG("grub-bhyve with default arguments");
|
||||
|
||||
if (devicesmap_out != NULL) {
|
||||
g_auto(virBuffer) devicemap = VIR_BUFFER_INITIALIZER;
|
||||
|
||||
/* Grub device.map (just for boot) */
|
||||
if (userdef != NULL) {
|
||||
virBhyveFormatGrubDevice(&devicemap, userdef);
|
||||
|
@ -244,7 +244,7 @@ static char *
|
||||
bhyveConnectGetSysinfo(virConnectPtr conn, unsigned int flags)
|
||||
{
|
||||
bhyveConnPtr privconn = conn->privateData;
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
@ -678,7 +678,7 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn,
|
||||
const char *xmlData,
|
||||
unsigned int flags)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
bhyveConnPtr privconn = conn->privateData;
|
||||
virDomainDefPtr def = NULL;
|
||||
virCommandPtr cmd = NULL, loadcmd = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user