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(a)redhat.com>
---
src/bhyve/bhyve_capabilities.c | 3 +--
src/conf/virdomainobjlist.c | 3 +--
src/conf/virnetworkobj.c | 12 ++++--------
src/conf/virnwfilterbindingobjlist.c | 3 +--
src/conf/virnwfilterobj.c | 3 +--
src/conf/virsecretobj.c | 3 +--
src/conf/virstorageobj.c | 6 ++----
src/openvz/openvz_conf.c | 3 +--
src/qemu/qemu_driver.c | 6 ++----
src/qemu/qemu_interop_config.c | 3 +--
src/security/security_selinux.c | 6 ++----
src/storage/storage_backend_iscsi.c | 3 +--
src/storage/storage_util.c | 18 +++++-------------
src/util/vircgroup.c | 7 ++-----
src/util/vircgroupv1.c | 4 +---
src/util/vircommand.c | 3 +--
src/util/virdevmapper.c | 3 +--
src/util/virfile.c | 12 ++++--------
src/util/virhook.c | 8 ++------
src/util/virhostcpu.c | 6 ++----
src/util/virnetdev.c | 3 +--
src/util/virnuma.c | 3 +--
src/util/virpci.c | 15 +++++----------
src/util/virprocess.c | 3 +--
src/util/virresctrl.c | 9 +++------
src/util/virscsi.c | 6 ++----
src/util/virscsihost.c | 3 +--
src/util/virusb.c | 3 +--
src/util/virutil.c | 6 ++----
src/util/virvhba.c | 9 +++------
tests/testutilsqemu.c | 6 ++----
tests/virschematest.c | 3 +--
tools/virt-host-validate-common.c | 3 +--
33 files changed, 60 insertions(+), 127 deletions(-)
diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c
index 8a9acf52b0..e9b4e5176d 100644
--- a/src/bhyve/bhyve_capabilities.c
+++ b/src/bhyve/bhyve_capabilities.c
@@ -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;
}
diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c
index e9a4b271df..9c10090b32 100644
--- a/src/conf/virdomainobjlist.c
+++ b/src/conf/virdomainobjlist.c
@@ -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;
}
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index 46205b163c..acf1442f88 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -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;
}
diff --git a/src/conf/virnwfilterbindingobjlist.c b/src/conf/virnwfilterbindingobjlist.c
index 4cbb62abfa..194348d062 100644
--- a/src/conf/virnwfilterbindingobjlist.c
+++ b/src/conf/virnwfilterbindingobjlist.c
@@ -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;
}
diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c
index fce402f907..a6a5aa01c7 100644
--- a/src/conf/virnwfilterobj.c
+++ b/src/conf/virnwfilterobj.c
@@ -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;
}
diff --git a/src/conf/virsecretobj.c b/src/conf/virsecretobj.c
index 146210fbe7..fda3702415 100644
--- a/src/conf/virsecretobj.c
+++ b/src/conf/virsecretobj.c
@@ -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;
}
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 219594582c..4aff62434f 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -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;
}
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 8f1740863c..1783dce233 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -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;
}
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f1191c1210..cb56fbbfcf 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -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;
}
diff --git a/src/qemu/qemu_interop_config.c b/src/qemu/qemu_interop_config.c
index 7edca7540a..f2d83eae93 100644
--- a/src/qemu/qemu_interop_config.c
+++ b/src/qemu/qemu_interop_config.c
@@ -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;
}
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 7d9e62a239..6681ce194b 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -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;
}
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index 436d5e09c7..45167e4490 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -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;
}
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 7eaf899883..5a5e517b15 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -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;
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index b1caf11f47..6ba030bf9b 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -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;
}
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 67b35c1b9a..61fb359f8d 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -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;
diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 6350e77523..5ae2ad9ef9 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -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;
}
diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
index f26d36832a..323102d36e 100644
--- a/src/util/virdevmapper.c
+++ b/src/util/virdevmapper.c
@@ -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;
}
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 442d2fab96..fc0021036a 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -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;
}
diff --git a/src/util/virhook.c b/src/util/virhook.c
index 119ad1aae6..aad3e667d3 100644
--- a/src/util/virhook.c
+++ b/src/util/virhook.c
@@ -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;
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index 4ae4dca067..c531d65f86 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -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);
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 91b12fc131..256179c052 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -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;
}
diff --git a/src/util/virnuma.c b/src/util/virnuma.c
index 5d40d13977..51a5d6e8a6 100644
--- a/src/util/virnuma.c
+++ b/src/util/virnuma.c
@@ -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;
}
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 1f679a7b45..b44208e05a 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -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;
}
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index 37413796b3..dccfc2558e 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -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;
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index 400c8e9981..aa466592fc 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -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;
}
diff --git a/src/util/virscsi.c b/src/util/virscsi.c
index 4dcd68d53a..256acc37fa 100644
--- a/src/util/virscsi.c
+++ b/src/util/virscsi.c
@@ -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;
}
diff --git a/src/util/virscsihost.c b/src/util/virscsihost.c
index 7d8e5299b8..c259e63000 100644
--- a/src/util/virscsihost.c
+++ b/src/util/virscsihost.c
@@ -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);
diff --git a/src/util/virusb.c b/src/util/virusb.c
index 3e7e4281a3..a8afd6e6f0 100644
--- a/src/util/virusb.c
+++ b/src/util/virusb.c
@@ -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;
diff --git a/src/util/virutil.c b/src/util/virutil.c
index 708c3cf9ef..41e92023fc 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -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;
}
diff --git a/src/util/virvhba.c b/src/util/virvhba.c
index df0691a658..471d94d3dd 100644
--- a/src/util/virvhba.c
+++ b/src/util/virvhba.c
@@ -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;
}
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 278587767f..5ae1d64337 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -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;
}
diff --git a/tests/virschematest.c b/tests/virschematest.c
index 0e587c3ff0..9a947f61f2 100644
--- a/tests/virschematest.c
+++ b/tests/virschematest.c
@@ -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;
}
diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-common.c
index 61284ae4da..a10ac03293 100644
--- a/tools/virt-host-validate-common.c
+++ b/tools/virt-host-validate-common.c
@@ -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 {
--
2.26.2