From 59d132f82569282f0cf2a10d80ce468f644c9871 Mon Sep 17 00:00:00 2001 From: Daria Phoebe Brashear Date: Sun, 12 Jan 2020 23:53:02 -0500 Subject: [PATCH] hdb: don't use lock_file name after free in open_lock_file --- lib/hdb/ndbm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/hdb/ndbm.c b/lib/hdb/ndbm.c index 5b2c07e5f..c5a862116 100644 --- a/lib/hdb/ndbm.c +++ b/lib/hdb/ndbm.c @@ -136,6 +136,7 @@ static krb5_error_code open_lock_file(krb5_context context, const char *db_name, int *fd) { char *lock_file; + int ret = 0; /* lock old and new databases */ asprintf(&lock_file, "%s.lock", db_name); @@ -145,14 +146,13 @@ open_lock_file(krb5_context context, const char *db_name, int *fd) } *fd = open(lock_file, O_RDWR | O_CREAT, 0600); - free(lock_file); if(*fd < 0) { - int ret = errno; + ret = errno; krb5_set_error_message(context, ret, "open(%s): %s", lock_file, strerror(ret)); - return ret; } - return 0; + free(lock_file); + return ret; }