Blame SOURCES/0018-libselinux-getdefaultcon-free-memory-on-multiple-sam.patch

ffbc92
From db69a3d3622005d3ffd62498eac8da1ded264874 Mon Sep 17 00:00:00 2001
ffbc92
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
ffbc92
Date: Mon, 3 May 2021 17:11:07 +0200
ffbc92
Subject: [PATCH] libselinux: getdefaultcon: free memory on multiple same
ffbc92
 arguments
ffbc92
MIME-Version: 1.0
ffbc92
Content-Type: text/plain; charset=UTF-8
ffbc92
Content-Transfer-Encoding: 8bit
ffbc92
ffbc92
Do not leak memory if program arguments get specified more than once.
ffbc92
ffbc92
Found by clang-anlyzer.
ffbc92
ffbc92
getdefaultcon.c:52:3: warning: Potential leak of memory pointed to by 'level' [unix.Malloc]
ffbc92
                fprintf(stderr,
ffbc92
                ^~~~~~~~~~~~~~~
ffbc92
getdefaultcon.c:52:3: warning: Potential leak of memory pointed to by 'role' [unix.Malloc]
ffbc92
                fprintf(stderr,
ffbc92
                ^~~~~~~~~~~~~~~
ffbc92
getdefaultcon.c:52:3: warning: Potential leak of memory pointed to by 'service' [unix.Malloc]
ffbc92
                fprintf(stderr,
ffbc92
                ^~~~~~~~~~~~~~~
ffbc92
ffbc92
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
ffbc92
---
ffbc92
 libselinux/utils/getdefaultcon.c | 3 +++
ffbc92
 1 file changed, 3 insertions(+)
ffbc92
ffbc92
diff --git a/libselinux/utils/getdefaultcon.c b/libselinux/utils/getdefaultcon.c
ffbc92
index 96a5a8c23656..957c1cb2e307 100644
ffbc92
--- a/libselinux/utils/getdefaultcon.c
ffbc92
+++ b/libselinux/utils/getdefaultcon.c
ffbc92
@@ -28,12 +28,15 @@ int main(int argc, char **argv)
ffbc92
 	while ((opt = getopt(argc, argv, "l:r:s:v")) > 0) {
ffbc92
 		switch (opt) {
ffbc92
 		case 'l':
ffbc92
+			free(level);
ffbc92
 			level = strdup(optarg);
ffbc92
 			break;
ffbc92
 		case 'r':
ffbc92
+			free(role);
ffbc92
 			role = strdup(optarg);
ffbc92
 			break;
ffbc92
 		case 's':
ffbc92
+			free(service);
ffbc92
 			service = strdup(optarg);
ffbc92
 			break;
ffbc92
 		case 'v':
ffbc92
-- 
ffbc92
2.32.0
ffbc92