ssFrom fbc09df31a1f89b02ae13b21c949728ad82f5713 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@redhat.com>
Date: Thu, 17 Mar 2022 13:00:44 +0100
Subject: [PATCH] libmount: fix possible memory leak in
 mnt_optstr_fix_secontext() [coverity scan]

Signed-off-by: Karel Zak <kzak@redhat.com>
---
 libmount/src/optstr.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/libmount/src/optstr.c b/libmount/src/optstr.c
index 16800f5..97fd6da 100644
--- a/libmount/src/optstr.c
+++ b/libmount/src/optstr.c
@@ -908,12 +908,16 @@ int mnt_optstr_fix_secontext(char **optstr,
 
 	/* create a quoted string from the raw context */
 	sz = strlen((char *) raw);
-	if (!sz)
+	if (!sz) {
+		freecon(raw);
 		return -EINVAL;
+	}
 
 	p = val = malloc(valsz + 3);
-	if (!val)
+	if (!val) {
+		freecon(raw);
 		return -ENOMEM;
+	}
 
 	*p++ = '"';
 	memcpy(p, raw, sz);
-- 
2.27.0

