Skip to content

Commit

Permalink
change DIR* int g_autoptr(DIR) where appropriate
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Laine Stump committed Nov 3, 2020
1 parent a61472a commit c0ae491
Show file tree
Hide file tree
Showing 34 changed files with 61 additions and 132 deletions.
3 changes: 1 addition & 2 deletions src/bhyve/bhyve_capabilities.c
Expand Up @@ -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);
Expand Down Expand Up @@ -171,7 +171,6 @@ virBhyveDomainCapsBuild(bhyveConnPtr conn,

cleanup:
VIR_FREE(firmwares);
VIR_DIR_CLOSE(dir);
virObjectUnref(cfg);
return caps;
}
Expand Down
3 changes: 1 addition & 2 deletions src/conf/virdomainobjlist.c
Expand Up @@ -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;
Expand Down Expand Up @@ -633,7 +633,6 @@ virDomainObjListLoadAllConfigs(virDomainObjListPtr doms,
}
}

VIR_DIR_CLOSE(dir);
virObjectRWUnlock(doms);
return ret;
}
Expand Down
12 changes: 4 additions & 8 deletions src/conf/virnetworkobj.c
Expand Up @@ -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;
Expand All @@ -1097,7 +1097,6 @@ virNetworkObjLoadAllState(virNetworkObjListPtr nets,
}

cleanup:
VIR_DIR_CLOSE(dir);
return ret;
}

Expand All @@ -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;
Expand All @@ -1132,7 +1131,6 @@ virNetworkObjLoadAllConfigs(virNetworkObjListPtr nets,
virNetworkObjEndAPI(&obj);
}

VIR_DIR_CLOSE(dir);
return ret;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1738,7 +1736,6 @@ virNetworkObjDeleteAllPorts(virNetworkObjPtr net,

ret = 0;
cleanup:
VIR_DIR_CLOSE(dh);
return ret;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1901,6 +1898,5 @@ virNetworkObjLoadAllPorts(virNetworkObjPtr net,

ret = 0;
cleanup:
VIR_DIR_CLOSE(dh);
return ret;
}
3 changes: 1 addition & 2 deletions src/conf/virnwfilterbindingobjlist.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions src/conf/virnwfilterobj.c
Expand Up @@ -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;
Expand All @@ -543,7 +543,6 @@ virNWFilterObjListLoadAllConfigs(virNWFilterObjListPtr nwfilters,
virNWFilterObjUnlock(obj);
}

VIR_DIR_CLOSE(dir);
return ret;
}

Expand Down
3 changes: 1 addition & 2 deletions src/conf/virsecretobj.c
Expand Up @@ -896,7 +896,7 @@ int
virSecretLoadAllConfigs(virSecretObjListPtr secrets,
const char *configDir)
{
DIR *dir = NULL;
g_autoptr(DIR) dir = NULL;
struct dirent *de;
int rc;

Expand Down Expand Up @@ -926,6 +926,5 @@ virSecretLoadAllConfigs(virSecretObjListPtr secrets,
virSecretObjEndAPI(&obj);
}

VIR_DIR_CLOSE(dir);
return 0;
}
6 changes: 2 additions & 4 deletions src/conf/virstorageobj.c
Expand Up @@ -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;
Expand All @@ -1726,7 +1726,6 @@ virStoragePoolObjLoadAllState(virStoragePoolObjListPtr pools,
virStoragePoolObjEndAPI(&obj);
}

VIR_DIR_CLOSE(dir);
return ret;
}

Expand All @@ -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;
Expand Down Expand Up @@ -1768,7 +1767,6 @@ virStoragePoolObjLoadAllConfigs(virStoragePoolObjListPtr pools,
VIR_FREE(autostartLink);
}

VIR_DIR_CLOSE(dir);
return ret;
}

Expand Down
6 changes: 1 addition & 5 deletions src/node_device/node_device_udev.c
Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -1171,9 +1170,6 @@ udevGetVDPACharDev(const char *sysfs_path,
break;
}
}

VIR_DIR_CLOSE(dir);

if (direrr < 0)
return -1;

Expand Down
3 changes: 1 addition & 2 deletions src/openvz/openvz_conf.c
Expand Up @@ -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;
Expand All @@ -1028,7 +1028,6 @@ static int openvzAssignUUIDs(void)
openvzSetUUID(vpsid);
}

VIR_DIR_CLOSE(dp);
VIR_FREE(conf_dir);
return ret;
}
Expand Down
6 changes: 2 additions & 4 deletions src/qemu/qemu_driver.c
Expand Up @@ -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;
Expand Down Expand Up @@ -457,7 +457,6 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm,

ret = 0;
cleanup:
VIR_DIR_CLOSE(dir);
virObjectUnlock(vm);
return ret;
}
Expand All @@ -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;
Expand Down Expand Up @@ -557,7 +556,6 @@ qemuDomainCheckpointLoad(virDomainObjPtr vm,

ret = 0;
cleanup:
VIR_DIR_CLOSE(dir);
virObjectUnlock(vm);
return ret;
}
Expand Down
3 changes: 1 addition & 2 deletions src/qemu/qemu_interop_config.c
Expand Up @@ -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;
Expand Down Expand Up @@ -79,7 +79,6 @@ qemuBuildFileList(virHashTablePtr files, const char *dir)

ret = 0;
cleanup:
VIR_DIR_CLOSE(dirp);
return ret;
}

Expand Down
6 changes: 2 additions & 4 deletions src/security/security_selinux.c
Expand Up @@ -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;
Expand All @@ -3487,7 +3487,6 @@ virSecuritySELinuxSetFileLabels(virSecurityManagerPtr mgr,
virReportSystemError(errno, _("Unable to label files under %s"),
path);

VIR_DIR_CLOSE(dir);
return ret;
}

Expand All @@ -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;
Expand All @@ -3531,7 +3530,6 @@ virSecuritySELinuxRestoreFileLabels(virSecurityManagerPtr mgr,
virReportSystemError(errno, _("Unable to restore file labels under %s"),
path);

VIR_DIR_CLOSE(dir);
return ret;
}

Expand Down
3 changes: 1 addition & 2 deletions src/storage/storage_backend_iscsi.c
Expand Up @@ -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;

Expand Down Expand Up @@ -122,7 +122,6 @@ virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
}

cleanup:
VIR_DIR_CLOSE(sysdir);
return ret;
}

Expand Down

0 comments on commit c0ae491

Please sign in to comment.