#include <config.h>
#include "virsh-nodedev.h"
+#include "virsh-util.h"
#include "internal.h"
#include "viralloc.h"
static bool
cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
{
- virNodeDevicePtr dev = NULL;
+ g_autoptr(virshNodeDevice) dev = NULL;
const char *from = NULL;
g_autofree char *buffer = NULL;
virshControl *priv = ctl->privData;
vshPrintExtra(ctl, _("Node device %s created from %s\n"),
virNodeDeviceGetName(dev), from);
- virNodeDeviceFree(dev);
return true;
}
static bool
cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
{
- virNodeDevice *dev = NULL;
+ g_autoptr(virshNodeDevice) dev = NULL;
bool ret = false;
const char *device_value = NULL;
ret = true;
cleanup:
- if (dev)
- virNodeDeviceFree(dev);
return ret;
}
if (list && list->devices) {
for (i = 0; i < list->ndevices; i++) {
- if (list->devices[i])
- virNodeDeviceFree(list->devices[i]);
+ virshNodeDeviceFree(list->devices[i]);
}
g_free(list->devices);
}
remove_entry:
/* the device has to be removed as it failed one of the filters */
- virNodeDeviceFree(list->devices[i]);
- list->devices[i] = NULL;
+ g_clear_pointer(&list->devices[i], virshNodeDeviceFree);
deleted++;
}
static bool
cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd)
{
- virNodeDevicePtr device = NULL;
+ g_autoptr(virshNodeDevice) device = NULL;
g_autofree char *xml = NULL;
const char *device_value = NULL;
bool ret = false;
ret = true;
cleanup:
- if (device)
- virNodeDeviceFree(device);
return ret;
}
{
const char *name = NULL;
const char *driverName = NULL;
- virNodeDevicePtr device;
+ g_autoptr(virshNodeDevice) device = NULL;
bool ret = true;
virshControl *priv = ctl->privData;
else
vshError(ctl, _("Failed to detach device %s"), name);
- virNodeDeviceFree(device);
return ret;
}
cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cmd)
{
const char *name = NULL;
- virNodeDevicePtr device;
+ g_autoptr(virshNodeDevice) device = NULL;
bool ret = true;
virshControl *priv = ctl->privData;
ret = false;
}
- virNodeDeviceFree(device);
return ret;
}
cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd)
{
const char *name = NULL;
- virNodeDevicePtr device;
+ g_autoptr(virshNodeDevice) device = NULL;
bool ret = true;
virshControl *priv = ctl->privData;
ret = false;
}
- virNodeDeviceFree(device);
return ret;
}
static bool
cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cmd)
{
- virNodeDevicePtr dev = NULL;
+ g_autoptr(virshNodeDevice) dev = NULL;
bool ret = false;
int eventId = -1;
int timeout = 0;
if (eventId >= 0 &&
virConnectNodeDeviceEventDeregisterAny(priv->conn, eventId) < 0)
ret = false;
- if (dev)
- virNodeDeviceFree(dev);
return ret;
}
static bool
cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
{
- virNodeDevice *dev = NULL;
+ g_autoptr(virshNodeDevice) dev = NULL;
bool ret = false;
const char *device_value = NULL;
ret = true;
cleanup:
- if (dev)
- virNodeDeviceFree(dev);
return ret;
}
static bool
cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
{
- virNodeDevice *dev = NULL;
+ g_autoptr(virshNodeDevice) dev = NULL;
const char *from = NULL;
g_autofree char *buffer = NULL;
virshControl *priv = ctl->privData;
vshPrintExtra(ctl, _("Node device '%s' defined from '%s'\n"),
virNodeDeviceGetName(dev), from);
- virNodeDeviceFree(dev);
return true;
}
cmdNodeDeviceStart(vshControl *ctl, const vshCmd *cmd)
{
const char *name = NULL;
- virNodeDevice *device;
+ g_autoptr(virshNodeDevice) device = NULL;
bool ret = true;
virshControl *priv = ctl->privData;
ret = false;
}
- virNodeDeviceFree(device);
return ret;
}
static bool
cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd)
{
- virNodeDevice *dev = NULL;
+ g_autoptr(virshNodeDevice) dev = NULL;
bool ret = false;
const char *name = NULL;
int autostart;
ret = true;
cleanup:
- if (dev)
- virNodeDeviceFree(dev);
return ret;
}
static bool
cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd)
{
- virNodeDevicePtr device = NULL;
+ g_autoptr(virshNodeDevice) device = NULL;
const char *device_value = NULL;
bool ret = false;
int autostart;
ret = true;
cleanup:
- if (device)
- virNodeDeviceFree(device);
return ret;
}