checkpolicy: free id in define_port_context()

Variable id is almost never freed in define_port_context().

This leak has been detected with gcc Address Sanitizer.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
Signed-off-by: James Carter <jwcart2@tycho.nsa.gov>
This commit is contained in:
Nicolas Iooss 2016-12-26 22:18:29 +01:00 committed by James Carter
parent c39289c9b7
commit da00246827

View file

@ -4899,8 +4899,7 @@ int define_port_context(unsigned int low, unsigned int high)
protocol = IPPROTO_DCCP; protocol = IPPROTO_DCCP;
} else { } else {
yyerror2("unrecognized protocol %s", id); yyerror2("unrecognized protocol %s", id);
free(newc); goto bad;
return -1;
} }
newc->u.port.protocol = protocol; newc->u.port.protocol = protocol;
@ -4909,13 +4908,11 @@ int define_port_context(unsigned int low, unsigned int high)
if (low > high) { if (low > high) {
yyerror2("low port %d exceeds high port %d", low, high); yyerror2("low port %d exceeds high port %d", low, high);
free(newc); goto bad;
return -1;
} }
if (parse_security_context(&newc->context[0])) { if (parse_security_context(&newc->context[0])) {
free(newc); goto bad;
return -1;
} }
/* Preserve the matching order specified in the configuration. */ /* Preserve the matching order specified in the configuration. */
@ -4945,9 +4942,11 @@ int define_port_context(unsigned int low, unsigned int high)
else else
policydbp->ocontexts[OCON_PORT] = newc; policydbp->ocontexts[OCON_PORT] = newc;
free(id);
return 0; return 0;
bad: bad:
free(id);
free(newc); free(newc);
return -1; return -1;
} }