Ensure that the directory is closed when opening chardev path for a vDPA device. Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx> --- src/node_device/node_device_udev.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index b1b8427c05..eb4ae22151 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1150,6 +1150,7 @@ udevGetVDPACharDev(const char *sysfs_path, struct dirent *entry; DIR *dir = NULL; int direrr; + int ret = -1; if (virDirOpenIfExists(&dir, sysfs_path) <= 0) return -1; @@ -1162,7 +1163,7 @@ udevGetVDPACharDev(const char *sysfs_path, virReportError(VIR_ERR_INTERNAL_ERROR, _("vDPA chardev path '%s' does not exist"), chardev); - return -1; + goto cleanup; } VIR_DEBUG("vDPA chardev is at '%s'", chardev); @@ -1172,9 +1173,13 @@ udevGetVDPACharDev(const char *sysfs_path, } if (direrr < 0) - return -1; + goto cleanup; - return 0; + ret = 0; + + cleanup: + VIR_DIR_CLOSE(dir); + return ret; } static int -- 2.26.2