28f609
From 599f1ec818d50ffc9690fea8c03b5fe278f30ed4 Mon Sep 17 00:00:00 2001
28f609
From: Vit Mojzis <vmojzis@redhat.com>
28f609
Date: Wed, 7 Dec 2022 09:19:29 +0100
28f609
Subject: [PATCH] libselinux/restorecon: Fix memory leak - xattr_value
28f609
28f609
Fix memory leak introduced by commit
28f609
 9a04499cebedac3f585c0240e6cf68f786ae62b7
28f609
 libselinux: Ignore missing directories when -i is used
28f609
28f609
Error: RESOURCE_LEAK:
28f609
 selinux_restorecon.c:804: alloc_fn: Storage is returned from allocation function "malloc".
28f609
 selinux_restorecon.c:804: var_assign: Assigning: "xattr_value" = storage returned from "malloc(fc_digest_len)".
28f609
 selinux_restorecon.c:825: leaked_storage: Variable "xattr_value" going out of scope leaks the storage it points to.
28f609
28f609
Resolves: rhbz#2137965
28f609
---
28f609
 libselinux/src/selinux_restorecon.c | 2 ++
28f609
 1 file changed, 2 insertions(+)
28f609
28f609
diff --git a/libselinux/src/selinux_restorecon.c b/libselinux/src/selinux_restorecon.c
28f609
index 2ff73db6..b3702764 100644
28f609
--- a/libselinux/src/selinux_restorecon.c
28f609
+++ b/libselinux/src/selinux_restorecon.c
28f609
@@ -822,6 +822,7 @@ int selinux_restorecon(const char *pathname_orig,
28f609
 				free(basename_cpy);
28f609
 				/* missing parent directory */
28f609
 				if (flags.ignore_noent && errno == ENOENT) {
28f609
+					free(xattr_value);
28f609
 					return 0;
28f609
 				}
28f609
 				goto realpatherr;
28f609
@@ -838,6 +839,7 @@ int selinux_restorecon(const char *pathname_orig,
28f609
 			if (!pathdnamer) {
28f609
 				free(basename_cpy);
28f609
 				if (flags.ignore_noent && errno == ENOENT) {
28f609
+					free(xattr_value);
28f609
 					return 0;
28f609
 				}
28f609
 				goto realpatherr;
28f609
-- 
28f609
2.37.3
28f609