Variable id is almost never freed in define_port_context().

This leak has been detected with gcc Address Sanitizer.

Signed-off-by: Nicolas Iooss <[email protected]>
---
 checkpolicy/policy_define.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/checkpolicy/policy_define.c b/checkpolicy/policy_define.c
index 2ad98c3c851e..ff902787c2aa 100644
--- a/checkpolicy/policy_define.c
+++ b/checkpolicy/policy_define.c
@@ -4899,6 +4899,7 @@ int define_port_context(unsigned int low, unsigned int 
high)
                protocol = IPPROTO_DCCP;
        } else {
                yyerror2("unrecognized protocol %s", id);
+               free(id);
                free(newc);
                return -1;
        }
@@ -4909,11 +4910,13 @@ int define_port_context(unsigned int low, unsigned int 
high)
 
        if (low > high) {
                yyerror2("low port %d exceeds high port %d", low, high);
+               free(id);
                free(newc);
                return -1;
        }
 
        if (parse_security_context(&newc->context[0])) {
+               free(id);
                free(newc);
                return -1;
        }
@@ -4945,9 +4948,11 @@ int define_port_context(unsigned int low, unsigned int 
high)
        else
                policydbp->ocontexts[OCON_PORT] = newc;
 
+       free(id);
        return 0;
 
       bad:
+       free(id);
        free(newc);
        return -1;
 }
-- 
2.11.0

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].

Reply via email to