diff mbox

[1/4] checkpolicy: always free id in define_type()

Message ID 20170121142613.12375-1-nicolas.iooss@m4x.org (mailing list archive)
State Not Applicable
Headers show

Commit Message

Nicolas Iooss Jan. 21, 2017, 2:26 p.m. UTC
In function define_type(), some error conditions between "id =
queue_remove(id_queue)" and "get_local_type(id, attr->s.value, 1)"
returned without freeing id. Fix theses memory leaks.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
 checkpolicy/policy_define.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

James Carter Jan. 23, 2017, 4:44 p.m. UTC | #1
On 01/21/2017 09:26 AM, Nicolas Iooss wrote:
> In function define_type(), some error conditions between "id =
> queue_remove(id_queue)" and "get_local_type(id, attr->s.value, 1)"
> returned without freeing id. Fix theses memory leaks.
>
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>

I applied all four of these.

Thanks,
Jim

> ---
>  checkpolicy/policy_define.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/checkpolicy/policy_define.c b/checkpolicy/policy_define.c
> index 6bfadbe59c91..03a0c18a9686 100644
> --- a/checkpolicy/policy_define.c
> +++ b/checkpolicy/policy_define.c
> @@ -1426,11 +1426,13 @@ int define_type(int alias)
>  		if (!attr) {
>  			/* treat it as a fatal error */
>  			yyerror2("attribute %s is not declared", id);
> +			free(id);
>  			return -1;
>  		}
>
>  		if (attr->flavor != TYPE_ATTRIB) {
>  			yyerror2("%s is a type, not an attribute", id);
> +			free(id);
>  			return -1;
>  		}
>
>
diff mbox

Patch

diff --git a/checkpolicy/policy_define.c b/checkpolicy/policy_define.c
index 6bfadbe59c91..03a0c18a9686 100644
--- a/checkpolicy/policy_define.c
+++ b/checkpolicy/policy_define.c
@@ -1426,11 +1426,13 @@  int define_type(int alias)
 		if (!attr) {
 			/* treat it as a fatal error */
 			yyerror2("attribute %s is not declared", id);
+			free(id);
 			return -1;
 		}
 
 		if (attr->flavor != TYPE_ATTRIB) {
 			yyerror2("%s is a type, not an attribute", id);
+			free(id);
 			return -1;
 		}