From eface6d31f8fd7c02eb0c6bc7e9d76efc0247b9c Mon Sep 17 00:00:00 2001 From: Viktor Dukhovni Date: Sun, 10 Feb 2013 06:15:35 +0000 Subject: [PATCH] Fix free before use in ipropd_master slaves-stats open function Signed-off-by: Love Hornquist Astrand --- lib/kadm5/ipropd_master.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/kadm5/ipropd_master.c b/lib/kadm5/ipropd_master.c index ba6e262b7..a0d90f9d9 100644 --- a/lib/kadm5/ipropd_master.c +++ b/lib/kadm5/ipropd_master.c @@ -813,26 +813,28 @@ static FILE * open_stats(krb5_context context) { char *statfile = NULL; - const char *fn; - int ret; + const char *fn = NULL; + FILE *out = NULL; + /* + * krb5_config_get_string_default() returs default value as-is, + * delay free() of "statfile" until we're done with "fn". + */ if (slave_stats_file) fn = slave_stats_file; - else { - ret = asprintf(&statfile, "%s/slaves-stats", hdb_db_dir(context)); - if (ret == -1) - return NULL; + else if (asprintf(&statfile, "%s/slaves-stats", hdb_db_dir(context)) != -1 + && statfile != NULL) fn = krb5_config_get_string_default(context, NULL, statfile, "kdc", "iprop-stats", NULL); + if (fn != NULL) + out = fopen(fn, "w"); + if (statfile != NULL) free(statfile); - } - if (fn == NULL) - return NULL; - return fopen(fn, "w"); + return out; } static void