change DIR* int g_autoptr(DIR) where appropriate

All of these conversions are trivial - VIR_DIR_CLOSE() (aka
virDirClose()) is called only once on the DIR*, and it happens just
before going out of scope.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Laine Stump 2020-10-25 17:50:51 -04:00
parent a61472aad8
commit c0ae4919e3
34 changed files with 61 additions and 132 deletions

View File

@ -134,7 +134,7 @@ virBhyveDomainCapsBuild(bhyveConnPtr conn,
{
virDomainCapsPtr caps = NULL;
unsigned int bhyve_caps = 0;
DIR *dir;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
size_t firmwares_alloc = 0;
virBhyveDriverConfigPtr cfg = virBhyveDriverGetConfig(conn);
@ -171,7 +171,6 @@ virBhyveDomainCapsBuild(bhyveConnPtr conn,
cleanup:
VIR_FREE(firmwares);
VIR_DIR_CLOSE(dir);
virObjectUnref(cfg);
return caps;
}

View File

@ -588,7 +588,7 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,
virDomainLoadConfigNotify notify,
void *opaque)
{
DIR *dir;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
int ret = -1;
int rc;
@ -633,7 +633,6 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,
}
}
VIR_DIR_CLOSE(dir);
virObjectRWUnlock(doms);
return ret;
}

View File

@ -1072,7 +1072,7 @@ virNetworkObjLoadAllState(virNetworkObjListPtr nets,
const char *stateDir,
virNetworkXMLOptionPtr xmlopt)
{
DIR *dir;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
int ret = -1;
int rc;
@ -1097,7 +1097,6 @@ virNetworkObjLoadAllState(virNetworkObjListPtr nets,
}
cleanup:
VIR_DIR_CLOSE(dir);
return ret;
}
@ -1108,7 +1107,7 @@ virNetworkObjLoadAllConfigs(virNetworkObjListPtr nets,
const char *autostartDir,
virNetworkXMLOptionPtr xmlopt)
{
DIR *dir;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
int ret = -1;
int rc;
@ -1132,7 +1131,6 @@ virNetworkObjLoadAllConfigs(virNetworkObjListPtr nets,
virNetworkObjEndAPI(&obj);
}
VIR_DIR_CLOSE(dir);
return ret;
}
@ -1707,7 +1705,7 @@ virNetworkObjDeleteAllPorts(virNetworkObjPtr net,
const char *stateDir)
{
g_autofree char *dir = NULL;
DIR *dh = NULL;
g_autoptr(DIR) dh = NULL;
struct dirent *de;
int rc;
int ret = -1;
@ -1738,7 +1736,6 @@ virNetworkObjDeleteAllPorts(virNetworkObjPtr net,
ret = 0;
cleanup:
VIR_DIR_CLOSE(dh);
return ret;
}
@ -1863,7 +1860,7 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net,
const char *stateDir)
{
g_autofree char *dir = NULL;
DIR *dh = NULL;
g_autoptr(DIR) dh = NULL;
struct dirent *de;
int ret = -1;
int rc;
@ -1901,6 +1898,5 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net,
ret = 0;
cleanup:
VIR_DIR_CLOSE(dh);
return ret;
}

View File

@ -300,7 +300,7 @@ int
virNWFilterBindingObjListLoadAllConfigs(virNWFilterBindingObjListPtr bindings,
const char *configDir)
{
DIR *dir;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
int ret = -1;
int rc;
@ -330,7 +330,6 @@ virNWFilterBindingObjListLoadAllConfigs(virNWFilterBindingObjListPtr bindings,
VIR_ERROR(_("Failed to load config for binding '%s'"), entry->d_name);
}
VIR_DIR_CLOSE(dir);
virObjectRWUnlock(bindings);
return ret;
}

View File

@ -524,7 +524,7 @@ int
virNWFilterObjListLoadAllConfigs(virNWFilterObjListPtr nwfilters,
const char *configDir)
{
DIR *dir;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
int ret = -1;
int rc;
@ -543,7 +543,6 @@ virNWFilterObjListLoadAllConfigs(virNWFilterObjListPtr nwfilters,
virNWFilterObjUnlock(obj);
}
VIR_DIR_CLOSE(dir);
return ret;
}

View File

@ -896,7 +896,7 @@ int
virSecretLoadAllConfigs(virSecretObjListPtr secrets,
const char *configDir)
{
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
struct dirent *de;
int rc;
@ -926,6 +926,5 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets,
virSecretObjEndAPI(&obj);
}
VIR_DIR_CLOSE(dir);
return 0;
}

View File

@ -1707,7 +1707,7 @@ int
virStoragePoolObjLoadAllState(virStoragePoolObjListPtr pools,
const char *stateDir)
{
DIR *dir;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
int ret = -1;
int rc;
@ -1726,7 +1726,6 @@ virStoragePoolObjLoadAllState(virStoragePoolObjListPtr pools,
virStoragePoolObjEndAPI(&obj);
}
VIR_DIR_CLOSE(dir);
return ret;
}
@ -1736,7 +1735,7 @@ virStoragePoolObjLoadAllConfigs(virStoragePoolObjListPtr pools,
const char *configDir,
const char *autostartDir)
{
DIR *dir;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
int ret;
int rc;
@ -1768,7 +1767,6 @@ virStoragePoolObjLoadAllConfigs(virStoragePoolObjListPtr pools,
VIR_FREE(autostartLink);
}
VIR_DIR_CLOSE(dir);
return ret;
}

View File

@ -1148,7 +1148,7 @@ udevGetVDPACharDev(const char *sysfs_path,
virNodeDevCapDataPtr data)
{
struct dirent *entry;
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
int direrr;
if (virDirOpenIfExists(&dir, sysfs_path) <= 0)
@ -1162,7 +1162,6 @@ udevGetVDPACharDev(const char *sysfs_path,
virReportError(VIR_ERR_INTERNAL_ERROR,
_("vDPA chardev path '%s' does not exist"),
chardev);
VIR_DIR_CLOSE(dir);
return -1;
}
VIR_DEBUG("vDPA chardev is at '%s'", chardev);
@ -1171,9 +1170,6 @@ udevGetVDPACharDev(const char *sysfs_path,
break;
}
}
VIR_DIR_CLOSE(dir);
if (direrr < 0)
return -1;

View File

@ -1003,7 +1003,7 @@ openvzSetUUID(int vpsid)
static int openvzAssignUUIDs(void)
{
DIR *dp;
g_autoptr(DIR) dp = NULL;
struct dirent *dent;
char *conf_dir;
int vpsid;
@ -1028,7 +1028,6 @@ static int openvzAssignUUIDs(void)
openvzSetUUID(vpsid);
}
VIR_DIR_CLOSE(dp);
VIR_FREE(conf_dir);
return ret;
}

View File

@ -357,7 +357,7 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm,
{
char *baseDir = (char *)data;
g_autofree char *snapDir = NULL;
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
virDomainSnapshotDefPtr def = NULL;
virDomainMomentObjPtr snap = NULL;
@ -457,7 +457,6 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm,
ret = 0;
cleanup:
VIR_DIR_CLOSE(dir);
virObjectUnlock(vm);
return ret;
}
@ -469,7 +468,7 @@ qemuDomainCheckpointLoad(virDomainObjPtr vm,
{
char *baseDir = (char *)data;
g_autofree char *chkDir = NULL;
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
virDomainCheckpointDefPtr def = NULL;
virDomainMomentObjPtr chk = NULL;
@ -557,7 +556,6 @@ qemuDomainCheckpointLoad(virDomainObjPtr vm,
ret = 0;
cleanup:
VIR_DIR_CLOSE(dir);
virObjectUnlock(vm);
return ret;
}

View File

@ -37,7 +37,7 @@ VIR_LOG_INIT("qemu.qemu_configs");
static int
qemuBuildFileList(virHashTablePtr files, const char *dir)
{
DIR *dirp;
g_autoptr(DIR) dirp = NULL;
struct dirent *ent = NULL;
int rc;
int ret = -1;
@ -79,7 +79,6 @@ qemuBuildFileList(virHashTablePtr files, const char *dir)
ret = 0;
cleanup:
VIR_DIR_CLOSE(dirp);
return ret;
}

View File

@ -3464,7 +3464,7 @@ virSecuritySELinuxSetFileLabels(virSecurityManagerPtr mgr,
int ret = 0;
struct dirent *ent;
char *filename = NULL;
DIR *dir;
g_autoptr(DIR) dir = NULL;
if ((ret = virSecuritySELinuxSetFilecon(mgr, path, seclabel->imagelabel, true)))
return ret;
@ -3487,7 +3487,6 @@ virSecuritySELinuxSetFileLabels(virSecurityManagerPtr mgr,
virReportSystemError(errno, _("Unable to label files under %s"),
path);
VIR_DIR_CLOSE(dir);
return ret;
}
@ -3509,7 +3508,7 @@ virSecuritySELinuxRestoreFileLabels(virSecurityManagerPtr mgr,
int ret = 0;
struct dirent *ent;
char *filename = NULL;
DIR *dir;
g_autoptr(DIR) dir = NULL;
if ((ret = virSecuritySELinuxRestoreFileLabel(mgr, path, true)))
return ret;
@ -3531,7 +3530,6 @@ virSecuritySELinuxRestoreFileLabels(virSecurityManagerPtr mgr,
virReportSystemError(errno, _("Unable to restore file labels under %s"),
path);
VIR_DIR_CLOSE(dir);
return ret;
}

View File

@ -90,7 +90,7 @@ virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
uint32_t *host)
{
int ret = -1;
DIR *sysdir = NULL;
g_autoptr(DIR) sysdir = NULL;
struct dirent *dirent = NULL;
int direrr;
@ -122,7 +122,6 @@ virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
}
cleanup:
VIR_DIR_CLOSE(sysdir);
return ret;
}

View File

@ -1920,7 +1920,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
bool loop)
{
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
DIR *dh;
g_autoptr(DIR) dh = NULL;
struct dirent *dent;
char *stablepath;
int opentries = 0;
@ -1963,7 +1963,6 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
stablepath = g_strdup_printf("%s/%s", def->target.path, dent->d_name);
if (virFileLinkPointsTo(stablepath, devpath)) {
VIR_DIR_CLOSE(dh);
return stablepath;
}
@ -1975,8 +1974,6 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
goto retry;
}
VIR_DIR_CLOSE(dh);
ret_strdup:
/* Couldn't find any matching stable link so give back
* the original non-stable dev path
@ -3505,7 +3502,7 @@ int
virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
{
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
DIR *dir;
g_autoptr(DIR) dir = NULL;
struct dirent *ent;
struct statvfs sb;
struct stat statbuf;
@ -3595,7 +3592,6 @@ virStorageBackendRefreshLocal(virStoragePoolObjPtr pool)
ret = 0;
cleanup:
VIR_DIR_CLOSE(dir);
return ret;
}
@ -3726,7 +3722,7 @@ getNewStyleBlockDevice(const char *lun_path,
const char *block_name G_GNUC_UNUSED,
char **block_device)
{
DIR *block_dir = NULL;
g_autoptr(DIR) block_dir = NULL;
struct dirent *block_dirent = NULL;
int retval = -1;
int direrr;
@ -3753,7 +3749,6 @@ getNewStyleBlockDevice(const char *lun_path,
retval = 0;
cleanup:
VIR_DIR_CLOSE(block_dir);
return retval;
}
@ -3799,7 +3794,7 @@ getBlockDevice(uint32_t host,
uint32_t lun,
char **block_device)
{
DIR *lun_dir = NULL;
g_autoptr(DIR) lun_dir = NULL;
struct dirent *lun_dirent = NULL;
int retval = -1;
int direrr;
@ -3839,7 +3834,6 @@ getBlockDevice(uint32_t host,
retval = 0;
cleanup:
VIR_DIR_CLOSE(lun_dir);
return retval;
}
@ -3968,7 +3962,7 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
int retval = 0;
uint32_t bus, target, lun;
const char *device_path = "/sys/bus/scsi/devices";
DIR *devicedir = NULL;
g_autoptr(DIR) devicedir = NULL;
struct dirent *lun_dirent = NULL;
char devicepattern[64];
int found = 0;
@ -4001,8 +3995,6 @@ virStorageBackendSCSIFindLUs(virStoragePoolObjPtr pool,
found++;
}
VIR_DIR_CLOSE(devicedir);
if (retval < 0)
return -1;

View File

@ -2303,7 +2303,7 @@ virCgroupGetCpuacctPercpuUsage(virCgroupPtr group, char **usage)
int
virCgroupRemoveRecursively(char *grppath)
{
DIR *grpdir;
g_autoptr(DIR) grpdir = NULL;
struct dirent *ent;
int rc = 0;
int direrr;
@ -2334,8 +2334,6 @@ virCgroupRemoveRecursively(char *grppath)
VIR_ERROR(_("Failed to readdir for %s (%d)"), grppath, errno);
}
VIR_DIR_CLOSE(grpdir);
VIR_DEBUG("Removing cgroup %s", grppath);
if (rmdir(grppath) != 0 && errno != ENOENT) {
rc = -errno;
@ -2471,7 +2469,7 @@ virCgroupKillRecursiveInternal(virCgroupPtr group,
int rc;
bool killedAny = false;
g_autofree char *keypath = NULL;
DIR *dp = NULL;
g_autoptr(DIR) dp = NULL;
struct dirent *ent;
int direrr;
VIR_DEBUG("group=%p path=%s signum=%d pids=%p",
@ -2524,7 +2522,6 @@ virCgroupKillRecursiveInternal(virCgroupPtr group,
ret = killedAny ? 1 : 0;
cleanup:
VIR_DIR_CLOSE(dp);
return ret;
}

View File

@ -880,7 +880,7 @@ virCgroupV1SetOwner(virCgroupPtr cgroup,
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
g_autofree char *base = NULL;
struct dirent *de;
DIR *dh = NULL;
g_autoptr(DIR) dh = NULL;
if (!((1 << i) & controllers))
continue;
@ -915,8 +915,6 @@ virCgroupV1SetOwner(virCgroupPtr cgroup,
base, uid, gid);
goto cleanup;
}
VIR_DIR_CLOSE(dh);
}
ret = 0;

View File

@ -452,7 +452,7 @@ static int
virCommandMassCloseGetFDsLinux(virCommandPtr cmd G_GNUC_UNUSED,
virBitmapPtr fds)
{
DIR *dp = NULL;
g_autoptr(DIR) dp = NULL;
struct dirent *entry;
const char *dirName = "/proc/self/fd";
int rc;
@ -479,7 +479,6 @@ virCommandMassCloseGetFDsLinux(virCommandPtr cmd G_GNUC_UNUSED,
ret = 0;
cleanup:
VIR_DIR_CLOSE(dp);
return ret;
}

View File

@ -169,7 +169,7 @@ virDMSanitizepath(const char *path)
g_autofree char *dmDirPath = NULL;
struct dirent *ent = NULL;
struct stat sb[2];
DIR *dh = NULL;
g_autoptr(DIR) dh = NULL;
const char *p;
char *ret = NULL;
@ -211,7 +211,6 @@ virDMSanitizepath(const char *path)
}
}
VIR_DIR_CLOSE(dh);
return ret;
}

View File

@ -669,7 +669,7 @@ static int virFileLoopDeviceOpenLoopCtl(char **dev_name, int *fd)
static int virFileLoopDeviceOpenSearch(char **dev_name)
{
int fd = -1;
DIR *dh = NULL;
g_autoptr(DIR) dh = NULL;
struct dirent *de;
char *looppath = NULL;
struct loop_info64 lo;
@ -726,7 +726,6 @@ static int virFileLoopDeviceOpenSearch(char **dev_name)
VIR_DEBUG("No free loop devices available");
VIR_FREE(looppath);
}
VIR_DIR_CLOSE(dh);
return fd;
}
@ -836,7 +835,7 @@ virFileNBDDeviceIsBusy(const char *dev_name)
static char *
virFileNBDDeviceFindUnused(void)
{
DIR *dh;
g_autoptr(DIR) dh = NULL;
char *ret = NULL;
struct dirent *de;
int direrr;
@ -861,7 +860,6 @@ virFileNBDDeviceFindUnused(void)
_("No free NBD devices"));
cleanup:
VIR_DIR_CLOSE(dh);
return ret;
}
@ -979,7 +977,7 @@ int virFileNBDDeviceAssociate(const char *file,
*/
int virFileDeleteTree(const char *dir)
{
DIR *dh;
g_autoptr(DIR) dh = NULL;
struct dirent *de;
int ret = -1;
int direrr;
@ -1028,7 +1026,6 @@ int virFileDeleteTree(const char *dir)
ret = 0;
cleanup:
VIR_DIR_CLOSE(dh);
return ret;
}
@ -2954,7 +2951,7 @@ int virFileChownFiles(const char *name,
struct dirent *ent;
int ret = -1;
int direrr;
DIR *dir;
g_autoptr(DIR) dir = NULL;
if (virDirOpen(&dir, name) < 0)
return -1;
@ -2982,7 +2979,6 @@ int virFileChownFiles(const char *name,
ret = 0;
cleanup:
VIR_DIR_CLOSE(dir);
return ret;
}

View File

@ -143,7 +143,7 @@ static int
virHookCheck(int no, const char *driver)
{
int ret;
DIR *dir;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
g_autofree char *path = NULL;
g_autofree char *dir_path = NULL;
@ -199,8 +199,6 @@ virHookCheck(int no, const char *driver)
break;
}
VIR_DIR_CLOSE(dir);
return ret;
}
@ -341,7 +339,7 @@ virHookCall(int driver,
char **output)
{
int ret, script_ret;
DIR *dir;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
g_autofree char *path = NULL;
g_autofree char *dir_path = NULL;
@ -438,8 +436,6 @@ virHookCall(int driver,
virStringListAdd(&entries, entry_path);
}
VIR_DIR_CLOSE(dir);
if (ret < 0)
return -1;

View File

@ -308,7 +308,7 @@ virHostCPUParseNode(const char *node,
{
int ret = -1;
int processors = 0;
DIR *cpudir = NULL;
g_autoptr(DIR) cpudir = NULL;
struct dirent *cpudirent = NULL;
virBitmapPtr node_cpus_map = NULL;
virBitmapPtr sockets_map = NULL;
@ -443,7 +443,6 @@ virHostCPUParseNode(const char *node,
ret = processors;
cleanup:
VIR_DIR_CLOSE(cpudir);
if (cores_maps)
for (i = 0; i < sock_max; i++)
virBitmapFree(cores_maps[i]);
@ -611,7 +610,7 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
{
virBitmapPtr present_cpus_map = NULL;
virBitmapPtr online_cpus_map = NULL;
DIR *nodedir = NULL;
g_autoptr(DIR) nodedir = NULL;
struct dirent *nodedirent = NULL;
int nodecpus, nodecores, nodesockets, nodethreads, offline = 0;
int threads_per_subcore = 0;
@ -772,7 +771,6 @@ virHostCPUGetInfoPopulateLinux(FILE *cpuinfo,
ret = 0;
cleanup:
VIR_DIR_CLOSE(nodedir);
virBitmapFree(present_cpus_map);
virBitmapFree(online_cpus_map);
VIR_FREE(sysfs_nodedir);

View File

@ -2898,7 +2898,7 @@ virNetDevRDMAFeature(const char *ifname,
{
g_autofree char *eth_devpath = NULL;
g_autofree char *eth_res_buf = NULL;
DIR *dirp = NULL;
g_autoptr(DIR) dirp = NULL;
struct dirent *dp;
int ret = -1;
@ -2934,7 +2934,6 @@ virNetDevRDMAFeature(const char *ifname,
ret = 0;
cleanup:
VIR_DIR_CLOSE(dirp);
return ret;
}

View File

@ -740,7 +740,7 @@ virNumaGetPages(int node,
size_t *npages)
{
int ret = -1;
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
int direrr = 0;
struct dirent *entry;
unsigned int ntmp = 0;
@ -854,7 +854,6 @@ virNumaGetPages(int node,
*npages = ntmp;
ret = 0;
cleanup:
VIR_DIR_CLOSE(dir);
return ret;
}

View File

@ -432,7 +432,7 @@ virPCIDeviceIterDevices(virPCIDeviceIterPredicate predicate,
virPCIDevicePtr *matched,
void *data)
{
DIR *dir;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
int ret = 0;
int rc;
@ -480,7 +480,6 @@ virPCIDeviceIterDevices(virPCIDeviceIterPredicate predicate,
break;
}
}
VIR_DIR_CLOSE(dir);
return ret;
}
@ -1706,7 +1705,7 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev,
void *opaque)
{
g_autofree char *pcidir = NULL;
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
int ret = -1;
struct dirent *ent;
int direrr;
@ -1741,7 +1740,6 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev,
ret = 0;
cleanup:
VIR_DIR_CLOSE(dir);
return ret;
}
@ -1757,7 +1755,7 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
void *opaque)
{
g_autofree char *groupPath = NULL;
DIR *groupDir = NULL;
g_autoptr(DIR) groupDir = NULL;
int ret = -1;
struct dirent *ent;
int direrr;
@ -1790,7 +1788,6 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
ret = 0;
cleanup:
VIR_DIR_CLOSE(groupDir);
return ret;
}
@ -2388,7 +2385,7 @@ virPCIGetNetName(const char *device_link_sysfs_path,
g_autofree char *pcidev_sysfs_net_path = NULL;
g_autofree char *firstEntryName = NULL;
int ret = -1;
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
struct dirent *entry = NULL;
size_t i = 0;
@ -2461,7 +2458,6 @@ virPCIGetNetName(const char *device_link_sysfs_path,
}
}
cleanup:
VIR_DIR_CLOSE(dir);
return ret;
}
@ -2535,7 +2531,7 @@ virPCIGetMdevTypes(const char *sysfspath,
{
ssize_t ret = -1;
int dirret = -1;
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
g_autofree char *types_path = NULL;
g_autoptr(virMediatedDeviceType) mdev_type = NULL;
@ -2575,7 +2571,6 @@ virPCIGetMdevTypes(const char *sysfspath,
for (i = 0; i < ntypes; i++)
virMediatedDeviceTypeFree(mdev_types[i]);
VIR_FREE(mdev_types);
VIR_DIR_CLOSE(dir);
return ret;
}

View File

@ -616,7 +616,7 @@ virProcessGetAffinity(pid_t pid G_GNUC_UNUSED)
int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids)
{
int ret = -1;
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
int value;
struct dirent *ent;
g_autofree char *taskPath = NULL;
@ -647,7 +647,6 @@ int virProcessGetPids(pid_t pid, size_t *npids, pid_t **pids)
ret = 0;
cleanup:
VIR_DIR_CLOSE(dir);
if (ret < 0)
VIR_FREE(*pids);
return ret;

View File

@ -781,7 +781,7 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl)
static int
virResctrlGetInfo(virResctrlInfoPtr resctrl)
{
DIR *dirp = NULL;
g_autoptr(DIR) dirp = NULL;
int ret = -1;
ret = virDirOpenIfExists(&dirp, SYSFS_RESCTRL_PATH "/info");
@ -802,7 +802,6 @@ virResctrlGetInfo(virResctrlInfoPtr resctrl)
ret = 0;
cleanup:
VIR_DIR_CLOSE(dirp);
return ret;
}
@ -1900,7 +1899,7 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl)
virResctrlAllocPtr ret = NULL;
virResctrlAllocPtr alloc = NULL;
struct dirent *ent = NULL;
DIR *dirp = NULL;
g_autoptr(DIR) dirp = NULL;
int rv = -1;
if (virResctrlInfoIsEmpty(resctrl)) {
@ -1947,7 +1946,6 @@ virResctrlAllocGetUnused(virResctrlInfoPtr resctrl)
cleanup:
virObjectUnref(alloc);
VIR_DIR_CLOSE(dirp);
return ret;
error:
@ -2663,7 +2661,7 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
int ret = -1;
size_t i = 0;
unsigned long long val = 0;
DIR *dirp = NULL;
g_autoptr(DIR) dirp = NULL;
char *datapath = NULL;
char *filepath = NULL;
struct dirent *ent = NULL;
@ -2747,7 +2745,6 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
VIR_FREE(datapath);
VIR_FREE(filepath);
virResctrlMonitorStatsFree(stat);
VIR_DIR_CLOSE(dirp);
return ret;
}

View File

@ -106,7 +106,7 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix,
unsigned int target,
unsigned long long unit)
{
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
g_autofree char *path = NULL;
char *sg = NULL;
@ -129,7 +129,6 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix,
}
cleanup:
VIR_DIR_CLOSE(dir);
return sg;
}
@ -143,7 +142,7 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
unsigned int target,
unsigned long long unit)
{
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
struct dirent *entry;
g_autofree char *path = NULL;
char *name = NULL;
@ -165,7 +164,6 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix,
}
cleanup:
VIR_DIR_CLOSE(dir);
return name;
}

View File

@ -100,7 +100,7 @@ virSCSIHostFindByPCI(const char *sysfs_prefix,
{
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH;
struct dirent *entry = NULL;
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
char *host_link = NULL;
char *host_path = NULL;
char *p = NULL;
@ -157,7 +157,6 @@ virSCSIHostFindByPCI(const char *sysfs_prefix,
}
cleanup:
VIR_DIR_CLOSE(dir);
VIR_FREE(unique_path);
VIR_FREE(host_link);
VIR_FREE(host_path);

View File

@ -110,7 +110,7 @@ virUSBDeviceSearch(unsigned int vendor,
const char *vroot,
unsigned int flags)
{
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
bool found = false;
char *ignore = NULL;
struct dirent *de;
@ -180,7 +180,6 @@ virUSBDeviceSearch(unsigned int vendor,
ret = list;
cleanup:
VIR_DIR_CLOSE(dir);
if (!ret)
virObjectUnref(list);
return ret;

View File

@ -1621,7 +1621,7 @@ virMemoryMaxValue(bool capped)
bool
virHostHasIOMMU(void)
{
DIR *iommuDir = NULL;
g_autoptr(DIR) iommuDir = NULL;
struct dirent *iommuGroup = NULL;
bool ret = false;
int direrr;
@ -1638,7 +1638,6 @@ virHostHasIOMMU(void)
ret = true;
cleanup:
VIR_DIR_CLOSE(iommuDir);
return ret;
}
@ -1658,7 +1657,7 @@ char *
virHostGetDRMRenderNode(void)
{
char *ret = NULL;
DIR *driDir = NULL;
g_autoptr(DIR) driDir = NULL;
const char *driPath = "/dev/dri";
struct dirent *ent = NULL;
int dirErr = 0;
@ -1687,7 +1686,6 @@ virHostGetDRMRenderNode(void)
ret = g_strdup_printf("%s/%s", driPath, ent->d_name);
cleanup:
VIR_DIR_CLOSE(driDir);
return ret;
}

View File

@ -158,7 +158,7 @@ char *
virVHBAFindVportHost(const char *sysfs_prefix)
{
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH;
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
struct dirent *entry = NULL;
char *max_vports = NULL;
char *vports = NULL;
@ -220,7 +220,6 @@ virVHBAFindVportHost(const char *sysfs_prefix)
}
cleanup:
VIR_DIR_CLOSE(dir);
VIR_FREE(max_vports);
VIR_FREE(vports);
return ret;
@ -365,7 +364,7 @@ virVHBAGetHostByWWN(const char *sysfs_prefix,
{
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH;
struct dirent *entry = NULL;
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
char *ret = NULL;
if (virDirOpen(&dir, prefix) < 0)
@ -393,7 +392,6 @@ virVHBAGetHostByWWN(const char *sysfs_prefix,
}
cleanup:
VIR_DIR_CLOSE(dir);
return ret;
}
@ -411,7 +409,7 @@ virVHBAGetHostByFabricWWN(const char *sysfs_prefix,
{
const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_FC_HOST_PATH;
struct dirent *entry = NULL;
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
char *vport_create_path = NULL;
char *ret = NULL;
@ -443,7 +441,6 @@ virVHBAGetHostByFabricWWN(const char *sysfs_prefix,
}
cleanup:
VIR_DIR_CLOSE(dir);
VIR_FREE(vport_create_path);
return ret;
}

View File

@ -510,7 +510,7 @@ testQemuGetLatestCapsForArch(const char *arch,
const char *suffix)
{
struct dirent *ent;
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
int rc;
g_autofree char *fullsuffix = NULL;
unsigned long maxver = 0;
@ -558,7 +558,6 @@ testQemuGetLatestCapsForArch(const char *arch,
ret = g_strdup_printf("%s/%s", TEST_QEMU_CAPS_PATH, maxname);
cleanup:
VIR_DIR_CLOSE(dir);
return ret;
}
@ -606,7 +605,7 @@ testQemuCapsIterate(const char *suffix,
void *opaque)
{
struct dirent *ent;
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
int rc;
int ret = -1;
bool fail = false;
@ -667,7 +666,6 @@ testQemuCapsIterate(const char *suffix,
ret = 0;
cleanup:
VIR_DIR_CLOSE(dir);
return ret;
}

View File

@ -86,7 +86,7 @@ testSchemaDir(const char *schema,
const char *dir_path,
const char *filterstr)
{
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
struct dirent *ent;
int ret = 0;
int rc;
@ -128,7 +128,6 @@ testSchemaDir(const char *schema,
ret = -1;
}
VIR_DIR_CLOSE(dir);
return ret;
}

View File

@ -374,7 +374,7 @@ int virHostValidateIOMMU(const char *hvname,
} else if (ARCH_IS_PPC64(arch)) {
/* Empty Block */
} else if (ARCH_IS_S390(arch)) {
DIR *dir;
g_autoptr(DIR) dir = NULL;
/* On s390x, we skip the IOMMU check if there are no PCI
* devices (which is quite usual on s390x). If there are
@ -383,7 +383,6 @@ int virHostValidateIOMMU(const char *hvname,
if (!virDirOpen(&dir, "/sys/bus/pci/devices"))
return 0;
rc = virDirRead(dir, &dent, NULL);
VIR_DIR_CLOSE(dir);
if (rc <= 0)
return 0;
} else {