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