From: Peter Krempa Date: Mon, 19 May 2025 13:31:21 +0000 (+0200) Subject: virSecuritySELinuxRestoreFileLabels: Refactor variable freeing X-Git-Tag: v11.6.0-rc1~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bc8d70969222ce5c21bdf0a2e02072241eb0d5b;p=thirdparty%2Flibvirt.git virSecuritySELinuxRestoreFileLabels: Refactor variable freeing Declare 'filename' inside the loop that is using it and use automatic freeing. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- 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; }