#include <config.h>
#include "virsh-interface.h"
+#include "virsh-util.h"
#include <libxml/parser.h>
#include <libxml/xpath.h>
cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd)
{
bool ret = false;
- virInterfacePtr iface = NULL;
- virInterfacePtr iface_edited = NULL;
+ g_autoptr(virshInterface) iface = NULL;
+ g_autoptr(virshInterface) iface_edited = NULL;
unsigned int flags = VIR_INTERFACE_XML_INACTIVE;
virshControl *priv = ctl->privData;
ret = true;
cleanup:
- if (iface)
- virInterfaceFree(iface);
- if (iface_edited)
- virInterfaceFree(iface_edited);
-
return ret;
}
if (list && list->ifaces) {
for (i = 0; i < list->nifaces; i++) {
- if (list->ifaces[i])
- virInterfaceFree(list->ifaces[i]);
+ virshInterfaceFree(list->ifaces[i]);
}
g_free(list->ifaces);
}
static bool
cmdInterfaceName(vshControl *ctl, const vshCmd *cmd)
{
- virInterfacePtr iface;
+ g_autoptr(virshInterface) iface = NULL;
if (!(iface = virshCommandOptInterfaceBy(ctl, cmd, NULL, NULL,
VIRSH_BYMAC)))
return false;
vshPrint(ctl, "%s\n", virInterfaceGetName(iface));
- virInterfaceFree(iface);
return true;
}
static bool
cmdInterfaceMAC(vshControl *ctl, const vshCmd *cmd)
{
- virInterfacePtr iface;
+ g_autoptr(virshInterface) iface = NULL;
if (!(iface = virshCommandOptInterfaceBy(ctl, cmd, NULL, NULL,
VIRSH_BYNAME)))
return false;
vshPrint(ctl, "%s\n", virInterfaceGetMACString(iface));
- virInterfaceFree(iface);
return true;
}
static bool
cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd)
{
- virInterfacePtr iface;
+ g_autoptr(virshInterface) iface = NULL;
g_autofree char *dump = NULL;
unsigned int flags = 0;
if (!(iface = virshCommandOptInterface(ctl, cmd, NULL)))
return false;
- if (!(dump = virInterfaceGetXMLDesc(iface, flags))) {
- virInterfaceFree(iface);
+ if (!(dump = virInterfaceGetXMLDesc(iface, flags)))
return false;
- }
vshPrint(ctl, "%s", dump);
- virInterfaceFree(iface);
return true;
}
static bool
cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd)
{
- virInterfacePtr iface;
+ g_autoptr(virshInterface) iface = NULL;
const char *from = NULL;
g_autofree char *buffer = NULL;
unsigned int flags = 0;
vshPrintExtra(ctl, _("Interface %s defined from %s\n"),
virInterfaceGetName(iface), from);
- virInterfaceFree(iface);
return true;
}
static bool
cmdInterfaceUndefine(vshControl *ctl, const vshCmd *cmd)
{
- virInterfacePtr iface;
+ g_autoptr(virshInterface) iface = NULL;
const char *name;
if (!(iface = virshCommandOptInterface(ctl, cmd, &name)))
if (virInterfaceUndefine(iface) < 0) {
vshError(ctl, _("Failed to undefine interface %s"), name);
- virInterfaceFree(iface);
return false;
}
vshPrintExtra(ctl, _("Interface %s undefined\n"), name);
- virInterfaceFree(iface);
return true;
}
static bool
cmdInterfaceStart(vshControl *ctl, const vshCmd *cmd)
{
- virInterfacePtr iface;
+ g_autoptr(virshInterface) iface = NULL;
const char *name;
if (!(iface = virshCommandOptInterface(ctl, cmd, &name)))
if (virInterfaceCreate(iface, 0) < 0) {
vshError(ctl, _("Failed to start interface %s"), name);
- virInterfaceFree(iface);
return false;
}
vshPrintExtra(ctl, _("Interface %s started\n"), name);
- virInterfaceFree(iface);
return true;
}
static bool
cmdInterfaceDestroy(vshControl *ctl, const vshCmd *cmd)
{
- virInterfacePtr iface;
+ g_autoptr(virshInterface) iface = NULL;
const char *name;
if (!(iface = virshCommandOptInterface(ctl, cmd, &name)))
if (virInterfaceDestroy(iface, 0) < 0) {
vshError(ctl, _("Failed to destroy interface %s"), name);
- virInterfaceFree(iface);
return false;
}
vshPrintExtra(ctl, _("Interface %s destroyed\n"), name);
- virInterfaceFree(iface);
return false;
}
cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd)
{
bool ret = false;
- virInterfacePtr if_handle = NULL, br_handle = NULL;
+ g_autoptr(virshInterface) if_handle = NULL;
+ g_autoptr(virshInterface) br_handle = NULL;
const char *if_name, *br_name;
char *if_type = NULL, *if2_name = NULL, *delay_str = NULL;
bool stp = false, nostart = false;
ret = true;
cleanup:
- if (if_handle)
- virInterfaceFree(if_handle);
- if (br_handle)
- virInterfaceFree(br_handle);
VIR_FREE(if_xml);
VIR_FREE(br_xml);
VIR_FREE(if_type);
cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd)
{
bool ret = false;
- virInterfacePtr if_handle = NULL, br_handle = NULL;
+ g_autoptr(virshInterface) if_handle = NULL;
+ g_autoptr(virshInterface) br_handle = NULL;
const char *br_name;
char *if_type = NULL, *if_name = NULL;
bool nostart = false;
ret = true;
cleanup:
- if (if_handle)
- virInterfaceFree(if_handle);
- if (br_handle)
- virInterfaceFree(br_handle);
VIR_FREE(if_xml);
VIR_FREE(br_xml);
VIR_FREE(if_type);