virPCIDeviceReadID(virPCIDevicePtr dev, const char *id_name)
{
g_autofree char *path = NULL;
- char *id_str;
+ g_autofree char *id_str = NULL;
path = virPCIFile(dev->name, id_name);
return NULL;
/* Check for 0x suffix */
- if (id_str[0] != '0' || id_str[1] != 'x') {
- VIR_FREE(id_str);
+ if (id_str[0] != '0' || id_str[1] != 'x')
return NULL;
- }
/* Chop off the newline; we know the string is 7 bytes */
id_str[6] = '\0';
- return id_str;
+ return g_steal_pointer(&id_str);
}
bool
{
int ret = -1;
virPCIDeviceAddressListPtr addrList = opaque;
- virPCIDeviceAddressPtr copyAddr;
+ g_autofree virPCIDeviceAddressPtr copyAddr = NULL;
/* make a copy to insert onto the list */
copyAddr = g_new0(virPCIDeviceAddress, 1);
ret = 0;
cleanup:
- VIR_FREE(copyAddr);
return ret;
}
virPCIDeviceAddressPtr
virPCIGetDeviceAddressFromSysfsLink(const char *device_link)
{
- virPCIDeviceAddressPtr bdf = NULL;
+ g_autofree virPCIDeviceAddressPtr bdf = NULL;
g_autofree char *config_address = NULL;
g_autofree char *device_path = NULL;
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to parse PCI config address '%s'"),
config_address);
- VIR_FREE(bdf);
return NULL;
}
- return bdf;
+ return g_steal_pointer(&bdf);
}
/**
size_t i;
g_autofree char *totalvfs_file = NULL;
g_autofree char *totalvfs_str = NULL;
- virPCIDeviceAddressPtr config_addr = NULL;
+ g_autofree virPCIDeviceAddressPtr config_addr = NULL;
*virtual_functions = NULL;
*num_virtual_functions = 0;
*num_virtual_functions, sysfs_path);
ret = 0;
cleanup:
- VIR_FREE(config_addr);
return ret;
error:
size_t i;
size_t num_virt_fns = 0;
unsigned int max_virt_fns = 0;
- virPCIDeviceAddressPtr vf_bdf = NULL;
+ g_autofree virPCIDeviceAddressPtr vf_bdf = NULL;
virPCIDeviceAddressPtr *virt_fns = NULL;
if (!(vf_bdf = virPCIGetDeviceAddressFromSysfsLink(vf_sysfs_device_link)))
VIR_FREE(virt_fns[i]);
VIR_FREE(virt_fns);
- VIR_FREE(vf_bdf);
-
return ret;
}
char **pfname,
int *vf_index)
{
- virPCIDeviceAddressPtr pf_config_address = NULL;
+ g_autofree virPCIDeviceAddressPtr pf_config_address = NULL;
g_autofree char *pf_sysfs_device_path = NULL;
g_autofree char *vfname = NULL;
g_autofree char *vfPhysPortID = NULL;
ret = 0;
cleanup:
- VIR_FREE(pf_config_address);
-
return ret;
}