From 4bc8d70969222ce5c21bdf0a2e02072241eb0d5b Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 19 May 2025 15:31:21 +0200 Subject: [PATCH] virSecuritySELinuxRestoreFileLabels: Refactor variable freeing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Declare 'filename' inside the loop that is using it and use automatic freeing. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/security/security_selinux.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index f042da4a13..854e46954e 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -3698,7 +3698,6 @@ virSecuritySELinuxRestoreFileLabels(virSecurityManager *mgr, { int ret = 0; struct dirent *ent; - char *filename = NULL; g_autoptr(DIR) dir = NULL; if ((ret = virSecuritySELinuxRestoreFileLabel(mgr, path, true))) @@ -3711,9 +3710,8 @@ virSecuritySELinuxRestoreFileLabels(virSecurityManager *mgr, return -1; while ((ret = virDirRead(dir, &ent, path)) > 0) { - filename = g_strdup_printf("%s/%s", path, ent->d_name); + g_autofree char *filename = g_strdup_printf("%s/%s", path, ent->d_name); ret = virSecuritySELinuxRestoreFileLabel(mgr, filename, true); - VIR_FREE(filename); if (ret < 0) break; } -- 2.47.2