diff mbox series

gssd: Closed a memory leak in find_keytab_entry()

Message ID 20200212190515.7443-1-steved@redhat.com (mailing list archive)
State New, archived
Headers show
Series gssd: Closed a memory leak in find_keytab_entry() | expand

Commit Message

Steve Dickson Feb. 12, 2020, 7:05 p.m. UTC
When 'adhostoverride' is "not set", which
is most of the time, adhostoverride is not freed.

Signed-off-by: Steve Dickson <steved@redhat.com>
---
 utils/gssd/krb5_util.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Steve Dickson Feb. 14, 2020, 9:41 p.m. UTC | #1
On 2/12/20 2:05 PM, Steve Dickson wrote:
> When 'adhostoverride' is "not set", which
> is most of the time, adhostoverride is not freed.
> 
> Signed-off-by: Steve Dickson <steved@redhat.com>
Committed... 

stesved
> ---
>  utils/gssd/krb5_util.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/utils/gssd/krb5_util.c b/utils/gssd/krb5_util.c
> index a1c43d2..85f60ae 100644
> --- a/utils/gssd/krb5_util.c
> +++ b/utils/gssd/krb5_util.c
> @@ -799,7 +799,7 @@ find_keytab_entry(krb5_context context, krb5_keytab kt,
>  	int tried_all = 0, tried_default = 0, tried_upper = 0;
>  	krb5_principal princ;
>  	const char *notsetstr = "not set";
> -	char *adhostoverride;
> +	char *adhostoverride = NULL;
>  
>  
>  	/* Get full target hostname */
> @@ -827,7 +827,6 @@ find_keytab_entry(krb5_context context, krb5_keytab kt,
>  				adhostoverride);
>  	        /* No overflow: Windows cannot handle strings longer than 19 chars */
>  	        strcpy(myhostad, adhostoverride);
> -		free(adhostoverride);
>  	} else {
>  	        strcpy(myhostad, myhostname);
>  	        for (i = 0; myhostad[i] != 0; ++i) {
> @@ -836,6 +835,8 @@ find_keytab_entry(krb5_context context, krb5_keytab kt,
>  	        myhostad[i] = '$';
>  	        myhostad[i+1] = 0;
>  	}
> +	if (adhostoverride)
> +		krb5_free_string(context, adhostoverride);
>  
>  	if (!srchost) {
>  		retval = get_full_hostname(myhostname, myhostname, sizeof(myhostname));
>
diff mbox series

Patch

diff --git a/utils/gssd/krb5_util.c b/utils/gssd/krb5_util.c
index a1c43d2..85f60ae 100644
--- a/utils/gssd/krb5_util.c
+++ b/utils/gssd/krb5_util.c
@@ -799,7 +799,7 @@  find_keytab_entry(krb5_context context, krb5_keytab kt,
 	int tried_all = 0, tried_default = 0, tried_upper = 0;
 	krb5_principal princ;
 	const char *notsetstr = "not set";
-	char *adhostoverride;
+	char *adhostoverride = NULL;
 
 
 	/* Get full target hostname */
@@ -827,7 +827,6 @@  find_keytab_entry(krb5_context context, krb5_keytab kt,
 				adhostoverride);
 	        /* No overflow: Windows cannot handle strings longer than 19 chars */
 	        strcpy(myhostad, adhostoverride);
-		free(adhostoverride);
 	} else {
 	        strcpy(myhostad, myhostname);
 	        for (i = 0; myhostad[i] != 0; ++i) {
@@ -836,6 +835,8 @@  find_keytab_entry(krb5_context context, krb5_keytab kt,
 	        myhostad[i] = '$';
 	        myhostad[i+1] = 0;
 	}
+	if (adhostoverride)
+		krb5_free_string(context, adhostoverride);
 
 	if (!srchost) {
 		retval = get_full_hostname(myhostname, myhostname, sizeof(myhostname));