]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: fix possible memory leak in mnt_optstr_fix_secontext() [coverity scan]
authorKarel Zak <kzak@redhat.com>
Thu, 17 Mar 2022 12:00:44 +0000 (13:00 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 17 Mar 2022 12:00:44 +0000 (13:00 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/optstr.c

index 224293f65c302db35d788f961f7662fb7164b8ae..5acc94eaec1fbdd86bb016e11502861d4b9fa083 100644 (file)
@@ -915,12 +915,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);