diff mbox

libsepol: fix memory leak in sepol_bool_query()

Message ID 20170913081642.7260-1-jzarsky@redhat.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Jan.Zarsky.jzarsky@redhat.com Sept. 13, 2017, 8:16 a.m. UTC
From: Jan Zarsky <jzarsky@redhat.com>

When sepol_bool_query() returns NULL response, variable name is not
freed. Fix this by calling free() before returning.

Signed-off-by: Jan Zarsky <jzarsky@redhat.com>
---
 libsepol/src/booleans.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Stephen Smalley Sept. 20, 2017, 8:30 p.m. UTC | #1
On Wed, 2017-09-13 at 10:16 +0200, Jan.Zarsky.jzarsky@redhat.com wrote:
> From: Jan Zarsky <jzarsky@redhat.com>
> 
> When sepol_bool_query() returns NULL response, variable name is not
> freed. Fix this by calling free() before returning.
> 
> Signed-off-by: Jan Zarsky <jzarsky@redhat.com>

Thanks, applied.

> ---
>  libsepol/src/booleans.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/libsepol/src/booleans.c b/libsepol/src/booleans.c
> index c914a28..30fcf29 100644
> --- a/libsepol/src/booleans.c
> +++ b/libsepol/src/booleans.c
> @@ -155,6 +155,7 @@ int sepol_bool_query(sepol_handle_t * handle,
>  	booldatum = hashtab_search(policydb->p_bools.table, name);
>  	if (!booldatum) {
>  		*response = NULL;
> +		free(name);
>  		return STATUS_SUCCESS;
>  	}
>
diff mbox

Patch

diff --git a/libsepol/src/booleans.c b/libsepol/src/booleans.c
index c914a28..30fcf29 100644
--- a/libsepol/src/booleans.c
+++ b/libsepol/src/booleans.c
@@ -155,6 +155,7 @@  int sepol_bool_query(sepol_handle_t * handle,
 	booldatum = hashtab_search(policydb->p_bools.table, name);
 	if (!booldatum) {
 		*response = NULL;
+		free(name);
 		return STATUS_SUCCESS;
 	}