diff mbox series

gssd: Use krb5_free_string() instead of free()

Message ID 20200226190221.24885-1-steved@redhat.com (mailing list archive)
State New, archived
Headers show
Series gssd: Use krb5_free_string() instead of free() | expand

Commit Message

Steve Dickson Feb. 26, 2020, 7:02 p.m. UTC
Commit ae9e9760 plugged up some memory leaks
by freeing memory via free(2). The proper
way to free memory that has been allocated by
krb5 functions is with krb5_free_string()

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

Comments

Steve Dickson Feb. 27, 2020, 3:45 p.m. UTC | #1
On 2/26/20 2:02 PM, Steve Dickson wrote:
> Commit ae9e9760 plugged up some memory leaks
> by freeing memory via free(2). The proper
> way to free memory that has been allocated by
> krb5 functions is with krb5_free_string()
> 
> Signed-off-by: Steve Dickson <steved@redhat.com>
Committed... (tag: nfs-utils-2-4-4-rc1)

steved.
> ---
>  utils/gssd/krb5_util.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/utils/gssd/krb5_util.c b/utils/gssd/krb5_util.c
> index 85f60ae..8c73748 100644
> --- a/utils/gssd/krb5_util.c
> +++ b/utils/gssd/krb5_util.c
> @@ -484,7 +484,7 @@ gssd_get_single_krb5_cred(krb5_context context,
>  	if (ccache)
>  		krb5_cc_close(context, ccache);
>  	krb5_free_cred_contents(context, &my_creds);
> -	free(k5err);
> +	krb5_free_string(context, k5err);
>  	return (code);
>  }
>  
> @@ -723,7 +723,7 @@ gssd_search_krb5_keytab(krb5_context context, krb5_keytab kt,
>  				 "we failed to unparse principal name: %s\n",
>  				 k5err);
>  			k5_free_kt_entry(context, kte);
> -			free(k5err);
> +			krb5_free_string(context, k5err);
>  			k5err = NULL;
>  			continue;
>  		}
> @@ -770,7 +770,7 @@ gssd_search_krb5_keytab(krb5_context context, krb5_keytab kt,
>  	if (retval < 0)
>  		retval = 0;
>    out:
> -	free(k5err);
> +	krb5_free_string(context, k5err);
>  	return retval;
>  }
>  
> @@ -927,7 +927,7 @@ find_keytab_entry(krb5_context context, krb5_keytab kt,
>  				k5err = gssd_k5_err_msg(context, code);
>  				printerr(1, "%s while building principal for '%s'\n",
>  					 k5err, spn);
> -				free(k5err);
> +				krb5_free_string(context, k5err);
>  				k5err = NULL;
>  				continue;
>  			}
> @@ -937,7 +937,7 @@ find_keytab_entry(krb5_context context, krb5_keytab kt,
>  				k5err = gssd_k5_err_msg(context, code);
>  				printerr(3, "%s while getting keytab entry for '%s'\n",
>  					 k5err, spn);
> -				free(k5err);
> +				krb5_free_string(context, k5err);
>  				k5err = NULL;
>  				/*
>  				 * We tried the active directory machine account
> @@ -986,7 +986,7 @@ out:
>  		k5_free_default_realm(context, default_realm);
>  	if (realmnames)
>  		krb5_free_host_realm(context, realmnames);
> -	free(k5err);
> +	krb5_free_string(context, k5err);
>  	return retval;
>  }
>  
> @@ -1249,7 +1249,7 @@ gssd_destroy_krb5_machine_creds(void)
>  			printerr(0, "WARNING: %s while resolving credential "
>  				    "cache '%s' for destruction\n", k5err,
>  				    ple->ccname);
> -			free(k5err);
> +			krb5_free_string(context, k5err);
>  			k5err = NULL;
>  			continue;
>  		}
> @@ -1258,13 +1258,13 @@ gssd_destroy_krb5_machine_creds(void)
>  			k5err = gssd_k5_err_msg(context, code);
>  			printerr(0, "WARNING: %s while destroying credential "
>  				    "cache '%s'\n", k5err, ple->ccname);
> -			free(k5err);
> +			krb5_free_string(context, k5err);
>  			k5err = NULL;
>  		}
>  	}
>  	krb5_free_context(context);
>    out:
> -	free(k5err);
> +	krb5_free_string(context, k5err);
>  }
>  
>  /*
> @@ -1347,7 +1347,7 @@ out_free_kt:
>  out_free_context:
>  	krb5_free_context(context);
>  out:
> -	free(k5err);
> +	krb5_free_string(context, k5err);
>  	return retval;
>  }
>  
>
diff mbox series

Patch

diff --git a/utils/gssd/krb5_util.c b/utils/gssd/krb5_util.c
index 85f60ae..8c73748 100644
--- a/utils/gssd/krb5_util.c
+++ b/utils/gssd/krb5_util.c
@@ -484,7 +484,7 @@  gssd_get_single_krb5_cred(krb5_context context,
 	if (ccache)
 		krb5_cc_close(context, ccache);
 	krb5_free_cred_contents(context, &my_creds);
-	free(k5err);
+	krb5_free_string(context, k5err);
 	return (code);
 }
 
@@ -723,7 +723,7 @@  gssd_search_krb5_keytab(krb5_context context, krb5_keytab kt,
 				 "we failed to unparse principal name: %s\n",
 				 k5err);
 			k5_free_kt_entry(context, kte);
-			free(k5err);
+			krb5_free_string(context, k5err);
 			k5err = NULL;
 			continue;
 		}
@@ -770,7 +770,7 @@  gssd_search_krb5_keytab(krb5_context context, krb5_keytab kt,
 	if (retval < 0)
 		retval = 0;
   out:
-	free(k5err);
+	krb5_free_string(context, k5err);
 	return retval;
 }
 
@@ -927,7 +927,7 @@  find_keytab_entry(krb5_context context, krb5_keytab kt,
 				k5err = gssd_k5_err_msg(context, code);
 				printerr(1, "%s while building principal for '%s'\n",
 					 k5err, spn);
-				free(k5err);
+				krb5_free_string(context, k5err);
 				k5err = NULL;
 				continue;
 			}
@@ -937,7 +937,7 @@  find_keytab_entry(krb5_context context, krb5_keytab kt,
 				k5err = gssd_k5_err_msg(context, code);
 				printerr(3, "%s while getting keytab entry for '%s'\n",
 					 k5err, spn);
-				free(k5err);
+				krb5_free_string(context, k5err);
 				k5err = NULL;
 				/*
 				 * We tried the active directory machine account
@@ -986,7 +986,7 @@  out:
 		k5_free_default_realm(context, default_realm);
 	if (realmnames)
 		krb5_free_host_realm(context, realmnames);
-	free(k5err);
+	krb5_free_string(context, k5err);
 	return retval;
 }
 
@@ -1249,7 +1249,7 @@  gssd_destroy_krb5_machine_creds(void)
 			printerr(0, "WARNING: %s while resolving credential "
 				    "cache '%s' for destruction\n", k5err,
 				    ple->ccname);
-			free(k5err);
+			krb5_free_string(context, k5err);
 			k5err = NULL;
 			continue;
 		}
@@ -1258,13 +1258,13 @@  gssd_destroy_krb5_machine_creds(void)
 			k5err = gssd_k5_err_msg(context, code);
 			printerr(0, "WARNING: %s while destroying credential "
 				    "cache '%s'\n", k5err, ple->ccname);
-			free(k5err);
+			krb5_free_string(context, k5err);
 			k5err = NULL;
 		}
 	}
 	krb5_free_context(context);
   out:
-	free(k5err);
+	krb5_free_string(context, k5err);
 }
 
 /*
@@ -1347,7 +1347,7 @@  out_free_kt:
 out_free_context:
 	krb5_free_context(context);
 out:
-	free(k5err);
+	krb5_free_string(context, k5err);
 	return retval;
 }