From edfa4955d88968e730fd3b69b0645fc108e1ad35 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 24 Oct 2024 23:26:53 +0200 Subject: [PATCH] device_id: close only opened dir After more of opendir, make sure 'dir' is closed only when it's been opened. --- lib/device/device_id.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/device/device_id.c b/lib/device/device_id.c index 0ac656922..06788db32 100644 --- a/lib/device/device_id.c +++ b/lib/device/device_id.c @@ -1359,7 +1359,7 @@ static void devices_file_backup(struct cmd_context *cmd, char *fc, char *fb, tim { struct dirent *de; struct dirent **namelist = NULL; - DIR *dir; + DIR *dir = NULL; FILE *fp = NULL; struct tm *tm; char dirpath[PATH_MAX]; @@ -1512,7 +1512,7 @@ out: if (fp && fclose(fp)) stack; - if (closedir(dir)) + if (dir && closedir(dir)) log_sys_debug("closedir", dirpath); }